Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to you make a custom walkspeed system with FE?

Asked by 5 years ago
Edited 5 years ago

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)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad

Answer this question