Help with random event

Hi there,

I am making a trick or treat system for a Halloween event in a game I work on. I have the getting treats part finished, but I do not know how I would make the trick happen. For the trick it would just subtract your candy amount.

Script (so far):

local debounce = true

game.Players.PlayerAdded:Connect(function(player)
local LS = Instance.new(“Folder”)
LS.Name = “leaderstats”
LS.Parent = player

local candy = Instance.new("IntValue") 
candy.Name = "Candy" 
candy.Parent = LS
candy.Value = 0
end)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
if debounce == true then
debounce = false
print (player.Name)
script.Parent.DoorBell:Play()
wait(3)
local random = math.random(1, 5)
player.leaderstats.Candy.Value = player.leaderstats.Candy.Value + random
wait(60)
debounce = true
end
end)``

If you’re looking to randomly decide between tricking a player or treating one, use

math.random(1, someinterval) --The lower the second interval the higher chance it will trick.

And then change based on what integer it chose, Example Below

local chosenNumber = math.random(1, 10)
if chosenNumber == 1 then
warn('Tricked!')
else
warn('Treated!')
end

Is this what you were asking for?

Yes, thank you, it works perfectly

You’re welcome! I hope you can do what you want now!

Make sure to mark the solution for others with a similar problem!