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

How would you make a GUI change a player's walkspeed by the player's choice?

Asked by
1ov3y0u 51
5 years ago

I have all the GUI set up. It's just that I don't know how to change the player's walkspeed if you were to use a TextBox and a TextButton.

2 answers

Log in to vote
0
Answered by
SmartNode 383 Moderation Voter
5 years ago

Textbox, use .FocusLost and connect it to the function. I believe one of the arguments are EnterPressed which is a Boolean (sends true if the focus was lost via the Enter key) Then get the textbox’s text and fire a remote to the server with the walkspeed amount. After that get on the server and change the players walkspeed with the provided argument.

Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

Put a LocalScript in the Text Button. Put the following code in:

script.Parent.MouseButton1Down:Connect(function()
    game.ReplicatedStorage.ChangeSpeed:FireServer(script.Parent.Parent.TextBox.Text)
end)

Then, make a RemoteEvent in ReplicatedStorage called "ChangeSpeed".

Finally, put a Script in ServerScriptService and put the following code in it:

game.ReplicatedStorage.ChangeSpeed.OnServerEvent:Connect(function(player,value)
    if value:IsA("Number") then
        if value > 0 and value < 100 then -- Set 100 to the max speed
            if player.Character.Humanoid then
                player.Character.Humanoid.WalkSpeed = value
            end
        elseif value > 0 then
             if player.Character.Humanoid then
                player.Character.Humanoid.WalkSpeed = 100
            end
        else if player.Character.Humanoid then
                player.Character.Humanoid.WalkSpeed = 0
            end
        end
    end
end)
0
ServerScriptService.Script:3: attempt to call method 'IsA' (a nil value) 1ov3y0u 51 — 5y

Answer this question