What i want to do is that the speed stacks up when stepped on another “part”.
Basically you start at 55 WalkSpeed
The Pad adds 45 WalkSpeed Makes it 100, but it should go back to 55 after time.
When stepped on another one the speed is 145 but should also go back to the default speed at 55.
I am very new to scripting and don’t even know many of the basics.
I don’t have a solution for the speed boost not returning to normal yet, but what I suggest might solve both problems at once.
You should detect if a player has already received a speed boost. This can be done in a few different ways. You can add a value inside the player, or store the values in the script.
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
if humanoid then
if not ReceivedSpeedBoost then --the "ReceivedSpeedBoost" variable can be changed or you could check the player's WalkSpeed
--code to handle giving speed boost and etc if needed
end
end
end
If i were to approach this issue, I’d add a localscript to startercharacterscripts and use the for i,v do loop to get every pad. Then, add a touched function. To get it globally, you’ll then use a script in serverscriptservice and add a remote event in replicatedstorage.
Similarly, like what @ Archenhailor said, you could add a value inside the player as a debounce. However, I’ll prob use a table for this.
localscript:
local debounce = {}
for i, pad in workspace.Pads:GetChildren() do -- folder in workspace called Pads with all the part/pad inside.
if pad:IsA("Part") then
pad.Touched:Connect(function(hit) --touched function
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
if hum and hum.Parent.Name == game.Players.LocalPlayer.Name then -- checks if local player touches a pad
if not table.find(debounce, pad) then -- debounce
table.insert(debounce, pad)
game.ReplicatedStorage.RemoteEvent:FireServer()
wait(3)
table.remove(debounce, table.find(debounce,pad))
end
end
end)
end
end
Then, in script you could get the player’s walkspeed and do:
local event = game.ReplicatedStorage.RemoteEvent
event.OnServerEvent:Connect(function(plr)
plr.Character.Humanoid.WalkSpeed += 45
wait(3) -- how long the boost last
plr.Character.Humanoid.WalkSpeed -= 45
end)