I have this script for looting. Whenever the player clicks it, it does a math.random and gives them a random item. The problem is that I want to add a cooldown, but I don’t know how. Help?
local Detector = script.Parent.ClickDetector
local ItemsStorage = game.ReplicatedStorage.Items
Detector.MouseClick:Connect(function(Player)
local character = Player.Character
local humanoid = character.Humanoid
local PickUp = humanoid:LoadAnimation(script.PickUpAnim)
local randomnumber = math.random(1, 5)
if randomnumber == 5 then
PickUp:Play()
local Clone = ItemsStorage.Clothing.DBlueJeans:Clone()
Clone.Parent = Player.Character
end
if randomnumber == 4 then
PickUp:Play()
local Clone = ItemsStorage.Clothing.DBrownJeans:Clone()
Clone.Parent = Player.Character
end
if randomnumber == 3 then
PickUp:Play()
local Clone = ItemsStorage.Clothing.DWhiteTShirt:Clone()
Clone.Parent = Player.Character
end
if randomnumber == 2 then
PickUp:Play()
local Clone = ItemsStorage.Clothing.RedFlannelShirt:Clone()
Clone.Parent = Player.Character
end
if randomnumber == 1 then
PickUp:Play()
local Clone = ItemsStorage.Clothing.FishingHat:Clone()
Clone.Parent = Player.Character
end
end)