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!

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

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.

Log in to vote
0
Answered by 5 years ago
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)
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 >

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