local bool = false
local X = 2 -- Replace with your desired wait time in seconds
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not bool then
bool = true
hit.Parent.Humanoid.WalkSpeed -= 18
wait(X)
bool = false
end
end)
How do I make this script ONLY PUT A TIMER ON A SINGLE PLAYER so the rest won’t be affected by the cool down.
How would I also make it so if the players speed is less than 1 it will turn into 1.
I might have a solution for your problem. You can create a table with every player that has a cooldown.
Let me write a script for you:
local check = {} -- creates table
local X = 2
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not table.find(check, player) then
table.insert(check, player) -- place player in timeout
hit.Parent.Humanoid.WalkSpeed -= 18
wait(X)
local index = table.find(check, player) -- get index of player
table.remove(check, index) -- remove player out of timeout
end
end)
ServerScriptService is for server sided scripts aka scripts meant for server use you should add the script into the part which is suppsoed to be touched
roblox is hitting me with the warning and ban hammer for voice chat even though i clearly and obviously did nothing. It’s so foolish I can’t work on my games. It’s such a foolish way of moderation im going to have to send out emails all this nonsense.
You can just put it in a script that is child of the part.
Also i just saw i forgot something in the script, i hadn’t even defined the variable ‘player’!
Here’s a script in which you can do everything you want, including the things you asked for later:
local check = {} -- creates table
local X = 2
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and not table.find(check, hit.Parent) then
table.insert(check, hit.Parent) -- place player in timeout
if hit.Parent.Humanoid.WalkSpeed - 18 < 1 then
hit.Parent.Humanoid.Health = 0
else
hit.Parent.Humanoid.WalkSpeed -= 18
end
wait(X)
local index = table.find(check, hit.Parent) -- get index of player
table.remove(check, index) -- remove player out of timeout
end
end)
I tested it, and it works for me! Tell me what you think, and hope this helped.
Change it to :FindFirstChildOfClass instead because it can see Humanoid.
So this is how it should be:
local bool = false
local X = 2 -- Replace with your desired wait time in seconds
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildOfClass("Humanoid") and not bool then
bool = true
hit.Parent.Humanoid.WalkSpeed -= 18
wait(X)
bool = false
end
end)