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

How to make a Button (Part w/ Click Detector) that gives speed? I am stuck.

Asked by 5 years ago
Edited 5 years ago

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.

0
you are using a click detector or a text button? Lazarix9 245 — 5y
0
Assuming the word 'button' is a gui. XviperIink 428 — 5y
0
@XviperIink 's answer below is good.. read my comment on her post User#23252 26 — 5y

4 answers

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

Well it is very simple!

01local Player = game.Players.LocalPlayer -- getting the player
02local Character = Player.Character -- getting the players' character
03 
04local Button = script.Parent -- where the button is located
05 
06Button.MouseButton1Click:Connect(function) -- When button is press
07    if Player and Character then -- check if player is alive and exist
08        -- If alive exist then
09        Character.Humanoid.WalkSpeed = 20 -- Change "20" to the speed you want default 16
10    end
11end)

Hope it helps!

The question changed soooo:

1local Part = script.Parent
2local CD = Part.ClickDetector -- CD == ClickDetector
3 
4CD.MouseClick:Connect(function(Player))
5    local Character = Player.Character
6    if Character then
7        Character.Humanoid.WalkSpeed = 20 -- Change "20" to the speed you want default 16
8    end
9end)
0
this works only for client right? Lazarix9 245 — 5y
0
this would work but it's not serversided so it wouldn't really work. VitroxVox 884 — 5y
0
yeah Lazarix9 245 — 5y
0
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 XviperIink 428 — 5y
View all comments (4 more)
0
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.. User#23252 26 — 5y
0
Ok, let me try! :) Enbloxen 5 — 5y
0
Hello, I modified the new script abit and now it works properly. Each click gives you 10 speed now! Enbloxen 5 — 5y
0
Haha thanks, I didnt realised that "Mouse" was spelled wrongly. LOL XviperIink 428 — 5y
Ad
Log in to vote
0
Answered by
Lazarix9 245 Moderation Voter
5 years ago

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:

01local button = script.Parent
02local players = game:GetService("Players")
03local replicatedStorage = game:GetService("ReplicatedStorage")
04 
05button.MouseButton1Click:Connect(function()
06 
07    local player = players.LocalPlayer
08    local changeSpeedEvent = replicatedStorage:WaitForChild("ChangeSpeedEvent")
09 
10    changeSpeedEvent:FireServer()
11 
12 
13end)

and a server script inside ServerScriptService with this in it:

01local replicatedStorage = game:GetService("ReplicatedStorage")
02local changeSpeedEvent = replicatedStorage:WaitForChild("ChangeSpeedEvent")
03 
04local function onChangeSpeedEvent(player)
05 
06    local players = game:GetService("Players")
07 
08    local char = player.Character or player.CharacterAdded:Wait()
09 
10    char:WaitForChild("Humanoid").WalkSpeed = 2
11 
12end
13 
14changeSpeedEvent.OnServerEvent:Connect(onChangeSpeedEvent)
15 
16end)

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:

01local part = script.Parent
02local clickdetector = part:waitForChild("ClickDetector")
03 
04clickdetector.MouseClick:Connect(function(p)
05 
06    local char = p.Character or p.CharacterAdded:wait()
07 
08    char:WaitForChild("Humanoid").WalkSpeed = 6
09 
10end)

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.

Log in to vote
0
Answered by 5 years ago
1part.Touched:Connect(function(h)
2    local hum = h.Parent:FindFirstChild("Humanoid")
3    if hum then
4        hum.WalkSpeed = 25 -- change it to whatever you like!
5    end
6end)
0
he/she needs a GUI button controlled speed change, not a part touched function. VitroxVox 884 — 5y
Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
5 years ago
Edited 5 years ago

Hello i've used @XviperIink 's code cause then i don't need to remake the whole client sided script:

simple version:

LocalScript >

1local Button = script.Parent -- where the button is located
2 
3Button.MouseButton1Click:Connect(function) -- When button is press
4            local speed = 20 -- u can change this to anything.
5        game.ReplicatedStorage:WaitForChild("RemoteEvent"):Fire(speed)
6end)

ServerScript >

1local remote = Instance.new("RemoteEvent",game.ReplicatedStorage)
2 
3remote.OnServerEvent:Connect(function(player,speed)
4    local player = workspace:FindFirstChild(player.Name)
5    if player then
6        player.Humanoid.WalkSpeed = speed
7    end
8end)
0
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. XviperIink 428 — 5y
0
Uh it saves space so yes i will use it. VitroxVox 884 — 5y

Answer this question