I have tried to make a button that will give a player speed. However, I am not very good at scripting and tried some really stupid things, like: game.Workspace:FindFirstChild('Humanoid') which of course didn't work. It's for my upcoming game Universal Creative Centre. I have successfully made a script which turns on a ParticleEmitter and changes a Player Size, but I can't think of how to do the speed button thing.
How to make a Button (Part w/ Click Detector) that gives speed? I am stuck.
4 answers
Well it is very simple!
local Player = game.Players.LocalPlayer -- getting the player
local Character = Player.Character -- getting the players' character
local Button = script.Parent -- where the button is located
Button.MouseButton1Click:Connect(function) -- When button is press
if Player and Character then -- check if player is alive and exist
-- If alive exist then
Character.Humanoid.WalkSpeed = 20 -- Change "20" to the speed you want default 16
end
end)
Hope it helps!
The question changed soooo:
local Part = script.Parent
local CD = Part.ClickDetector -- CD == ClickDetector
CD.MouseClick:Connect(function(Player))
local Character = Player.Character
if Character then
Character.Humanoid.WalkSpeed = 20 -- Change "20" to the speed you want default 16
end
end)
8 comments
this works only for client right?
this would work but it's not serversided so it wouldn't really work.
yeah
Changing the walkspeed doesnt need to be server side. It can be done in client side and everyone would see the speed of the person in case you dont know. lol
this would work for both the client and the server.. how do you think you see speed hackers in FE games? almost all games with some sort of speeding mechanism don't use Remote Events to replicate to the server..
Ok, let me try! :)
Hello, I modified the new script abit and now it works properly. Each click gives you 10 speed now!
Haha thanks, I didnt realised that "Mouse" was spelled wrongly. LOL
part.Touched:Connect(function(h)
local hum = h.Parent:FindFirstChild("Humanoid")
if hum then
hum.WalkSpeed = 25 -- change it to whatever you like!
end
end)
1 comment
he/she needs a GUI button controlled speed change, not a part touched function.
Hello i've used @XviperIink 's code cause then i don't need to remake the whole client sided script:
simple version:
LocalScript >
local Button = script.Parent -- where the button is located
Button.MouseButton1Click:Connect(function) -- When button is press
local speed = 20 -- u can change this to anything.
game.ReplicatedStorage:WaitForChild("RemoteEvent"):Fire(speed)
end)
ServerScript >
local remote = Instance.new("RemoteEvent",game.ReplicatedStorage)
remote.OnServerEvent:Connect(function(player,speed)
local player = workspace:FindFirstChild(player.Name)
if player then
player.Humanoid.WalkSpeed = speed
end
end)
3 comments
Why would changing the speed of a humanoid need a remote event? it can just be change on the client and it would still work, no need so much trouble. And anyways DON"T use the second parameter for Instance.New.
Uh it saves space so yes i will use it.
Well i can see that you are new. https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296
If you want a GUI button, you need to set up some RemoteEvents first, so in ReplicatedStorage you'll put a RemoteEvent called "ChangeSpeedEvent".
Insert a local script inside of the text button and write this in it:
local button = script.Parent
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
button.MouseButton1Click:Connect(function()
local player = players.LocalPlayer
local changeSpeedEvent = replicatedStorage:WaitForChild("ChangeSpeedEvent")
changeSpeedEvent:FireServer()
end)
and a server script inside ServerScriptService with this in it:
local replicatedStorage = game:GetService("ReplicatedStorage")
local changeSpeedEvent = replicatedStorage:WaitForChild("ChangeSpeedEvent")
local function onChangeSpeedEvent(player)
local players = game:GetService("Players")
local char = player.Character or player.CharacterAdded:Wait()
char:WaitForChild("Humanoid").WalkSpeed = 2
end
changeSpeedEvent.OnServerEvent:Connect(onChangeSpeedEvent)
end)
What that does is listen to when the player clicks a text button from a local script, then it fires the event that you set up previously. The server script listens to when that event has been fired and when it is it gets the character from the player who fired it (who clicked the button) and it sets the WalkSpeed to the number.
If you want a button like a part that you click on, insert a click detector and a server script inside the part and write this inside the script:
local part = script.Parent
local clickdetector = part:waitForChild("ClickDetector")
clickdetector.MouseClick:Connect(function(p)
local char = p.Character or p.CharacterAdded:wait()
char:WaitForChild("Humanoid").WalkSpeed = 6
end)
What that does is it gets the player from argument p and gets the character and sets WalkSpeed in Humanoid to a number you want.
Hope we could help you.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
you are using a click detector or a text button?
Assuming the word 'button' is a gui.
@XviperIink 's answer below is good.. read my comment on her post