Hello! I’m making an RP game and I need to make sure that the sound when an object is touched can be produced only once a minute, how can I do this?
Here is my script :
script.Parent.Touched:Connect(function(hit)
local player=game.Players:FindFirstChild(hit.Parent.Name)
local sound = game.Workspace.Intercom["SoundA"]
local t = game.Teams:FindFirstChild("Prisoner")
local b = game.Teams:FindFirstChild("Criminal")
if player.Team == t then
sound:Play()
player.Team = b
end
end)
local time = 60
local debounce = false
script.Parent.Touched:Connect(function(hit)
if debounce == false then
debounce == true
local player=game.Players:FindFirstChild(hit.Parent.Name)
local sound = game.Workspace.Intercom["SoundA"]
local t = game.Teams:FindFirstChild("Prisoner")
local b = game.Teams:FindFirstChild("Criminal")
if player.Team == t then
sound:Play()
player.Team = b
wait(Time)
debounce =false
end)
end
end)
local touchDebounce = false
local debounceDuration = 60 -- 60 seconds / 1 minute
script.Parent.Touched:Connect(function(hit)
if touchDebounce then return end
touchDebounce = true
task.delay(debounceDuration, function()
touchDebounce = false
end)
local player=game.Players:FindFirstChild(hit.Parent.Name)
local sound = game.Workspace.Intercom["SoundA"]
local t = game.Teams:FindFirstChild("Prisoner")
local b = game.Teams:FindFirstChild("Criminal")
if player.Team == t then
sound:Play()
player.Team = b
end
end)