Walkspeed not changing?

Made a simple local script via a text button for sprinting. However for some reason even though the output is saying it’s changing the speed to 25 without errors, it doesn’t do it at all? Could anyone explain what’s wrong with this script

script.Parent.MouseButton1Down:Connect(function()
	local Players = game:GetService("Players")
	local walkspeed = Players.LocalPlayer.Character.Humanoid.WalkSpeed
	if walkspeed == 16 then
		walkspeed = 25
		print("walkspeed set to "..walkspeed)
	elseif walkspeed == 25 then
		walkspeed = 16
		print("walkspeed set to "..walkspeed)
		end
end)
cript.Parent.MouseButton1Down:Connect(function()
	local Players = game:GetService("Players")
	local walkspeed = Players.LocalPlayer.Character.Humanoid.WalkSpeed
	if walkspeed == 16 then
		walkspeed = 25
		print("walkspeed set to "..walkspeed)
	else
		walkspeed = 16
		print("walkspeed set to "..walkspeed)
	end
end)

try this

1 Like

tried it before and tried it after you suggesting it but it still doesn’t work. Any other ideas?

What do you mean by it not working. Is the player not moving any faster?

Try this:

script.Parent.MouseButton1Down:Connect(function()
	local Players = game:GetService("Players")
	local humanoid = Players.LocalPlayer.Character:FindFirstChild("Humanoid")
	if humanoid then
		if humanoid.WalkSpeed == 16 then
			humanoid.WalkSpeed = 25
			print("walkspeed set to "..humanoid.WalkSpeed)
		elseif humanoid.WalkSpeed == 25 then
			humanoid.WalkSpeed = 16
			print("walkspeed set to "..humanoid.WalkSpeed)
		end
	end
end)

I think it didn’t work because you were only changing the WalkSpeed variable, not the WalkSpeed property of the humanoid.

1 Like

There are no actual errors in the output however when i check through the explorer after pressing down on the text button thus activating the walkspeed change (at least it says that through the output because of the prints) it actually doesn’t display any change in the explorer and there is no noticable difference in playtesting (visually)

1 Like

script.Parent.MouseButton1Down:Connect(function()
        print(“Button pressed”)
	local Players = game:GetService("Players")
	local walkspeed = Players.LocalPlayer.Character.Humanoid.WalkSpeed
	if walkspeed == 16 then
		walkspeed = 25
		print("walkspeed set to "..walkspeed)
	elseif walkspeed == 25 then
		walkspeed = 16
		print("walkspeed set to "..walkspeed)
	end
end)

Also try:


script.Parent.MouseButton1Down:Connect(function()
	local Players = game:GetService("Players")
	if Players.LocalPlayer.Character.Humanoid.WalkSpeed == 16 then
	        Players.LocalPlayer.Character.Humanoid.WalkSpeed = 25
		print("walkspeed set to "..walkspeed)
	elseif Players.LocalPlayer.Character.Humanoid.WalkSpeed == 25 then
	        Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
		print("walkspeed set to "..walkspeed)
	end
end)

i’m unsure how to use events in this fashion (not particularly experienced with them, if at all) but @AxeI_c 's method of referencing the humanoid thru findfirstchild seems to have worked apparently. Don’t know why, maybe this is a bug or maybe I just am unaware of a very specific change related to this.

1 Like