Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how do i make this script have a cooldown instead of deleting itself?

Asked by 2 years ago

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)
0
like with a timer or aslong as the script is running? Pitched_mobile 191 — 2y

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
2 years ago

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)
Ad

Answer this question