Sprinting Script not working

Hey developers,
I’ve been trying to create a script that allows the user to sprint if clicked. I’m not very good at programming yet, so I’m having a bit of trouble and just can’t seem to understand why this isn’t working. I’ve looked at tutorials and other DevForum posts, but nothing seems to be working.

The whole point of it is one block travels from one side of the UI to the other while switching colors and allowing the player to sprint in-game, and turn it off whenever they’d like. Although, if you press it once it’ll freeze and nothing else will happen.

Here’s the script.

-- Local Script
local par = script.Parent
local player = game.Players.LocalPlayer

local on = false

local function NOW_RUNNING()
	if player.Character then
		player.Character.Humanoid.Walkspeed = 30
	end
end

local function NOW_WALKING()
	if player.Character then
		player.Character.Humanoid.Walkspeed = 16
	end
end

par.MouseButton1Click:Connect(function()
	local clickSound = game.Workspace:FindFirstChild("ClickSound")
	clickSound.Playing = true
	if on == false then
		par.Text = "On"
		par:TweenPosition(UDim2.new(0, 0,-0, 0),"Out","Sine",0.25)
		local function nowOn()
			local waitTime = 0.075
			par.BackgroundColor3 = Color3.fromRGB(0,255,0)
		end
		nowOn()
		game.Players.LocalPlayer.Character.Humanoid.Walkspeed = 30
		on = true
	elseif on == true then
		par.Text = "Off"
		par:TweenPosition(UDim2.new(0.513, 0,-0, 0),"Out","Sine",0.25)
		local function nowOff()
			local waitTime = 0.075
			par.BackgroundColor3 = Color3.fromRGB(255,0,0)
		end
		nowOff()
		game.Players.LocalPlayer.Character.Humanoid.Walkspeed = 16
		on = false
	end
end)

Any ideas that may be able to help?

Change

and

Into this

player.Character.Humanoid.WalkSpeed = 16

You forgot to uppercase the S in WalkSpeed. So change that in every walk speed you wrote.

I tested the code and it should work now.

1 Like

Thank you! Really glad that worked.