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

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

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

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.

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)

1 comment

0

ServerScriptService.Script:3: attempt to call method 'IsA' (a nil value)

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