i want to make this script have a cooldown instead of deleting itself after being touched, how would i go about making it do that?
local pointPart = script.Parent -- Gives small points local blue = Color3.fromRGB(0, 0, 255) -- Gives large points local green = Color3.fromRGB(0, 255, 0) -- Makes players lose points local red = Color3.fromRGB(255 ,0, 0) -- points given to players local smallPoints = 1 local largePoints = 3 local losePoints = 6 local Players = game:GetService("Players") local function givePoints(player) local currentColor = pointPart.Color local playerStats = player:WaitForChild("leaderstats") local playerPoints= playerStats:WaitForChild("Points") -- Gives player points based on the color of the part if currentColor == blue then playerPoints.Value = playerPoints.Value + smallPoints elseif currentColor == green then playerPoints.Value = playerPoints.Value + largePoints else playerPoints.Value = playerPoints.Value + losePoints end pointPart:Destroy() end local function partTouched(otherPart) local player = Players:GetPlayerFromCharacter(otherPart.Parent) if player then givePoints(player) end end pointPart.Touched:Connect(partTouched)
Try this
local pointPart = script.Parent local debounce = false -- Gives small points local blue = Color3.fromRGB(0, 0, 255) -- Gives large points local green = Color3.fromRGB(0, 255, 0) -- Makes players lose points local red = Color3.fromRGB(255 ,0, 0) -- points given to players local smallPoints = 1 local largePoints = 3 local losePoints = 6 local Players = game:GetService("Players") local function givePoints(player) if debounce == false debounce = true local currentColor = pointPart.Color local playerStats = player:WaitForChild("leaderstats") local playerPoints= playerStats:WaitForChild("Points") -- Gives player points based on the color of the part if currentColor == blue then playerPoints.Value = playerPoints.Value + smallPoints elseif currentColor == green then playerPoints.Value = playerPoints.Value + largePoints else playerPoints.Value = playerPoints.Value + losePoints end wait(3) -- Cooldown time debounce = false end end local function partTouched(otherPart) local player = Players:GetPlayerFromCharacter(otherPart.Parent) if player then givePoints(player) end end pointPart.Touched:Connect(partTouched)