Can someone help me convert this script so that the block can only be touched every 1 second or until touched by another team.
local Block = script.Parent
Block.Touched:Connect(function(toc)
if toc.Parent:FindFirstChild(“Humanoid”) then
local player = Players:GetPlayerFromCharacter(toc.Parent)
if player.TeamColor == BrickColor.new(“Lime green”) then
Block.Color = Color3.fromRGB(0, 255, 8)
game.StarterGui.Counter.Count.GreenCounter.Value__.Value = game.StarterGui.Counter.Count.GreenCounter.Value__.Value + 1
end
end
end)
I just want the script not to add more than +1 point to one team
If you are wanting to make the touched event fire every certain amount of time (in seconds), you would use a debounce.
Basic example:
local Block = script.Parent
local Debounce = false
local Cooldown = 1 -- The amount of seconds the touched event will fire
Block.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player and not Debounce then
Debounce = true
print("Part touched by player")
task.wait(Cooldown)
Debounce = false
end
end)
local Players = game:GetService(“Players”)
local Block = script.Parent
local lastTouched = nil
Block.Touched:Connect(function(toc)
if toc.Parent:FindFirstChild(“Humanoid”) then
local player = Players:GetPlayerFromCharacter(toc.Parent)
if player and player.TeamColor == BrickColor.new(“Lime green”) and lastTouched ~= player then
Block.Color = Color3.fromRGB(0, 255, 8)
game.StarterGui.Counter.Count.GreenCounter.Value__.Value += 1
lastTouched = player
wait(1) – Wait for 1 second before allowing another point to be scored
end
end
end)