Stuck on Textbox Walkspeed

I was working on a textbox that changes you’re walkspeed to whatever number is in the textbox I tried to do that but nothing would happen.


script.Parent.Focused:Connect(function(enter)
	if enter then
		Plr.Character.Humanoid.WalkSpeed = script.Parent.Text
	end
end

Don’t know what to do right now so…

1 Like

Do this:

script.Parent.Focused:Connect(function(enter)
	if enter then
		Plr.Character.Humanoid.WalkSpeed = tonumber(script.Parent.Text)
	end
end

That didn’t work either no errors printed :confused:

Instead of using the Focused event, use the FocusLost one instead:

script.Parent.FocusLost:Connect(function(enter)
    print("Lost focus")
	if enter then
        print("Entered result")
		Plr.Character.Humanoid.WalkSpeed = tonumber(script.Parent.Text)
	end
end

In addition to what @JackscarIitt said, you should probably add a pcall or something to make sure the player entered a number.

local num
xpcall(function()
num = tonumber(script.Parent.Text)
end, function(err)
warn("Error; "..err)
end)

Thanks man, I was going at that for a while now.

You’re fine! Just keep in mind that the Focused event does not have any parameters (Or the “enter” variable you used)

FocusLost does however, as I referenced earlier

1 Like