Ad
Log in to vote
0

My sprint script does not function, and returns no output?

Asked by 1 year ago

Breakdown: This script is designed for my upcoming RPG, and I am having an error, I spawn with 16 speed like normal, and how I would like. But, when I press shift my speed does not increase, and if it does its not by the correct increments.

Script:

repeat wait() until game.Loaded
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid

local running = script.Running

local plr = game.Players.LocalPlayer
local player = game.Players:FindFirstChild(plr.Name) 
repeat wait() until plr.Character
local character = game.Workspace:FindFirstChild(player.Name)
local mouse = plr:GetMouse()

mouse.KeyDown:connect(function (key)
    key = string.lower(key)
    if string.byte(key) == 48 then
        if running.Value == false then
            running.Value = true
            Humanoid.WalkSpeed = Player.ServerTraits.Statistics.Speed.Value * 0.01 + 16
        elseif running.Value == true then
            running.Value = false
            Humanoid.WalkSpeed = 16
        end
    end
end)
0
Pretty sure it's supposed to be string:byte not string.byte. Correct me if I am wrong. DesertusX 435 — 1y
0
I have a better solution to all of this. Easier to read instead of having all of those local variables. ifreakinlostmyacount 52 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

This is a sprint script I made a few weeks ago, it has animatios, but it broke the script if you consistantly spammed the shift button, so I got rid of them. Heres the localscript:

game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
    game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 35


    end
        end)

game:GetService("UserInputService").InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
    game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").WalkSpeed = 17
    end
        end)

Make sure to put this in StarterPlayer.StarterCharacterScripts as a local script

Please upvote if this is the solution to your problem C:

0
You could maunually add new walkspeeds after a wait() so like WalkSpeed = 35 WalkSpeed = 36 etc. This can give more opertunity in velocity... ifreakinlostmyacount 52 — 1y
Ad

Answer this question