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

How do you change a players speed from a GUI?

So, I'm trying to make a GUI that can alter the player's humanoid speed. I am using a Text Box to get the speed but it just says that I am comparing a number with a string. I'm quite confused on how to make this work! Any help is appreciated!

local player = game.Players.LocalPlayer.Name

script.Parent.submit.MouseButton1Click:Connect(function()
	local body = game.Workspace:FindFirstChild(player)
	local humanoid = body:FindFirstChild("Humanoid")
	if script.Parent.enterSpeed.Text >= 30 then
		if humanoid~=nil then
			local speed = script.Parent.enterSpeed.Text
			humanoid.WalkSpeed = speed
		end
	end
end)

https://gyazo.com/5a82c427c10cacf71ffa03cf3b0fe39f

1 comment

0

edit:- fixed link

1 answer

✓ Accepted answer

You're trying two different datatypes which aren't compatible, a string and a number. What you can do is utilize the tonumber() function and instead of doing

if script.Parent.enterSpeed.Text >= 30 then

if the text is nothing but a number then you can do,

if tonumber(script.Parent.enterSpeed.Text) >= 30 then

2 comments

0

Thanks so much!

0

-1 tonumber will return nil if the value cannot be converted to a string and will cause this code to error

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