I am making a GUI and want to make a textbox to choose walkspeed
My script is game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = script.Parent.Text
Here's a view of studio: https://vgy.me/bZsqjk.png
I am making a GUI and want to make a textbox to choose walkspeed
My script is game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = script.Parent.Text
Here's a view of studio: https://vgy.me/bZsqjk.png
The text of the TextBox is a string (text). You cannot just set it as the WalkSpeed. You need to turn the text into a number with a function called tonumber().
hum.WalkSpeed = tonumber(script.Parent.Text)
Note that this function returns nil if the number is invalid, so you may want to use a ternary statement like this, in order to prevent unnecessary errors:
hum.WalkSpeed = tonumber(script.Parent.Text) or hum.WalkSpeed
That way if tonumber() returns nil, it will set the WalkSpeed to the current WalkSpeed (so it will be like it has never changed)
Actually setting a number value like walkspeed to nil will just set it to 0.
nil = 0, not the current walkspeed
Yea same thing. Op probably doesn't want the walkspeed to set to 0 whenever someone makes a typo
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = tonumber(script.Parent.Text) did not work
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
walkspeed is a float and you are setting it to a string?
Do
tonumber(script.Parent.Text)