tech/game

21/07/31 Roblox Studio Tutorial (How To Change Player Sprint Speed)

tech-lover 2021. 7. 31. 10:25

3가지 방법 (On/Off, 수치변경, 키보드)

1. Roblox Studio Tutorial: Click To Sprint Button

 

https://youtu.be/N_MGzA3luXg

```

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

https://youtu.be/DVdXIviqUM0

```

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키를 누르는 동안 속도 올리기)

https://youtu.be/PPVC1iklsQk

```

local userInput = game:GetService("UserInputService")

local players = game:GetService("Players")

 

local sprintSpeed = 30 

local walkSpeed = 16 

local player = players.LocalPlayer

 

local function beginSprint(inputgameProcessed)

    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(inputgameProcessed)

    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(inputgameProcessed)

    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)

```