3가지 방법 (On/Off, 수치변경, 키보드)
1. Roblox Studio Tutorial: Click To Sprint Button
```
local button = script.Parent
local Player = game:GetService('Players')
local sprinting = false
local function sprint()
local player = Player.LocalPlayer
if sprinting then
sprinting = false
button.Text = 'Sprint: Off'
player.Character.Humanoid.WalkSpeed = 16
else
sprinting = true
button.Text = 'Sprint: On'
player.Character.Humanoid.WalkSpeed = 50
end
end
button.MouseButton1Click:Connect(sprint)
```
2. Roblox Studio Tutorial: Custom Sprint Button
```
local frame = script.Parent
local add = frame.add
local sub = frame.sub
local speed = frame.speed
local Player = game:GetService('Players')
local currentSpeed = 16
local maxSpeed = 50
local minSpeed = 0
local function addSpeed()
local player = Player.LocalPlayer
if currentSpeed < maxSpeed then
currentSpeed = currentSpeed + 1
speed.Text = 'Speed: '..currentSpeed
player.Character.Humanoid.WalkSpeed = currentSpeed
end
end
local function subSpeed()
local player = Player.LocalPlayer
if currentSpeed > minSpeed then
currentSpeed = currentSpeed - 1
speed.Text = 'Speed: '..currentSpeed
player.Character.Humanoid.WalkSpeed = currentSpeed
end
end
add.MouseButton1Click:Connect(addSpeed)
sub.MouseButton1Click:Connect(subSpeed)
```
3. 키보드 Shift to Sprint (Shift키를 누르는 동안 속도 올리기)
```
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local sprintSpeed = 30
local walkSpeed = 16
local player = players.LocalPlayer
local function beginSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftShift then
player.Character.Humanoid.WalkSpeed = sprintSpeed
end
end
end
end
local function endSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftShift then
player.Character.Humanoid.WalkSpeed = walkSpeed
end
end
end
end
userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)
```
- Letf Shift 키를 터치할 때마다 속도 변경
```
local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")
local sprintSpeed = 30
local walkSpeed = 16
local sprinting = false
local player = players.LocalPlayer
local function beginSprint(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
local keycode = input.KeyCode
if keycode == Enum.KeyCode.LeftShift then
sprinting = not sprinting
if sprinting then
player.Character.Humanoid.WalkSpeed = sprintSpeed
else
player.Character.Humanoid.WalkSpeed = walkSpeed
end
end
end
end
end
userInput.InputBegan:Connect(beginSprint)
```
'tech > game' 카테고리의 다른 글
21/07/31 Roblox Studio Tutorial: Doorway (0) | 2021.07.31 |
---|---|
21/07/31 Roblox Custom Animation (Player) (0) | 2021.07.31 |
21/07/31 HOW TO MOVE PLAYERS (0) | 2021.07.31 |
21/07/31 Roblox Studio Tutorial: How to Set Up Multiple Spawn Locations (0) | 2021.07.31 |
21/07/30 Roblox - How to make a simple roblox widget plugin (0) | 2021.07.30 |