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

How do I enable and disable WalkSpeed via a TextButton?

I’m pretty new to scripting so expect errors. I been trying to change WalkSpeed by a TextButton but everything failed and I don’t know why. Can someone help me? (All code is inside a LocalScript)

function WalkSpeed()
  game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 40
end

Extra Code (an error?)

script.Parent.TextButton.MouseButton1Click:connect(WalkSpeed)

3 comments

0

Are there any errors in the output?

0

Whats the error saying?

0

TestButton is not a valid member of TextButton. That is the error.

1 answer

This is happening due to that the script's parent is already a textbutton, WalkSpeed is a nil value, and remember to add a ) to the end so that function can be closed.

Try this code:

script.Parent.MouseButton1Click:Connect(function()
	  game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 40
         --Remember that WalkSpeed is a nil value so no function WalkSpeed()
	end)

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