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