Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

Pretty sure it's supposed to be string:byte not string.byte. Correct me if I am wrong.

0

I have a better solution to all of this. Easier to read instead of having all of those local variables.

1 answer

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:

1 comment

0

You could maunually add new walkspeeds after a wait() so like WalkSpeed = 35 WalkSpeed = 36 etc. This can give more opertunity in velocity...

This discussion is preserved as it was. New answers, comments, and votes are closed.