I am trying to make a custom walkspeed system. Here's how it works: There's a textbox where you type in a number in. The textbox has a value inside it. The textbox text should be in that value. But when I type in the number I want my walkspeed to be, it changes it to zero. Any help?
Here's what I've tried:
local speed = script.Parent.Speed.SpeedValue local textBox = speed.Parent local player = game.Players.LocalPlayer local playerGui = player.PlayerGui local walkspeedGui = playerGui.Sprint local function changeSpeed() local text = textBox.Text if text ~= nil then textBox.Text = speed.Value local humanoid = player.Character:FindFirstChild("Humanoid") if humanoid ~= nil then humanoid.WalkSpeed = speed.Value end end end textBox.FocusLost:Connect(function(enterPressed) changeSpeed() end)
its because your doing it the wrong way ex, textBox.Text = speed.Value
is actually setting the text to the value instead. also you dont need to check if :FindFirstChild()
returns nil.
local speed = script.Parent.Speed.SpeedValue local textBox = speed.Parent local player = game.Players.LocalPlayer local playerGui = player.PlayerGui local walkspeedGui = playerGui.Sprint local function changeSpeed() local text = textBox.Text if text then speed.Value = tonumber(textBox.Text) -- call tonumber on strings. local humanoid = player.Character:FindFirstChild("Humanoid") if humanoid then humanoid.WalkSpeed = speed.Value end end end textBox.FocusLost:Connect(function(enterPressed) changeSpeed() end)