Run script not working

I made a running script and don’t know what’s the issue.

I have a LocalScript inside a TextButton inside a Frame inside a GUI.

I don’t have any idea why my running script doesn’t work, it doesn’t show any errors or warnings in the output.

Here’s the script that I made I just don’t understand what I did wrong…

local plr = game.Players.LocalPlayer --Get's the player
local char = plr.Character --Get's the player's model
local hum = char:WaitForChild("Humanoid") --Get's the humanoid
local WS = hum.WalkSpeed --No need to explain this one

script.Parent.MouseButton1Click:Connect(function(run) --Script parent is a TextButton
--Check's if the player is walking or not
	if WS == 20 then 
		WS = 50
	elseif WS == 50 then
		WS = 20
	end
end)

Instead of WS, try if hum.WalkSpeed == int.

I tried to do that before, but it didn’t work.

Is script.Parent the TextButton? Also try remove run from the function.
Edit: Default WalkSpeed is 16, not 20. Maybe that is the case.

you are setting an int not a property
try

local plr = game.Players.LocalPlayer --Get's the player
local char = plr.Character --Get's the player's model
local hum = char:WaitForChild("Humanoid") --Get's the humanoid
--local WS = hum.WalkSpeed --No need to explain this one

script.Parent.MouseButton1Click:Connect(function(run) --Script parent is a TextButton
--Check's if the player is walking or not
	if hum.WalkSpeed == 20 then 
		hum.WalkSpeed = 50
	elseif hum.WalkSpeed == 50 then
		hum.WalkSpeed = 20
	end
end)
1 Like

Fixed your code:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:WaitForChild("Humanoid")

script.Parent.MouseButton1Click:Connect(function()
	if hum.WalkSpeed == 16 then 
		hum.WalkSpeed = 50
	elseif hum.WalkSpeed == 50 then
		hum.WalkSpeed = 16
	end
end)

The script is inside a TextButton.

I tested the code and it worked, thanks!

Mark the post that resolved your OP as a solution.

I did that, unless there’s a way to close the post.

Right, I assume you marked the wrong post then, since I tested theirs and it doesn’t work, mine however works.

Both scripts do the same thing, I don’t see any diffrences.

local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local char = plr.Character or plr.CharacterAdded:Wait()
    local hum = char:WaitForChild("Humanoid")

    hum.WalkSpeed = math.abs(hum.WalkSpeed - 50) + 16
end)

I would do it like this, works if you respawn the character now
also you don’t need an if statement for this

20 is not the default WalkSpeed meaning that you’re checking for something that the player isn’t defaulted to. Meaning if you try and use that script they posted, it will not change the players WalkSpeed.

I changed the player’s main speed to 20, I went to StarterPlayer then changed the DefaultWalkSpeed to 20.

I just realized that
changed it to 16

I was just fixing their simple error, but yes I may do it that way if I were to use it for other purposed.