Hello,
So I am making a game, in which when you click on the item on the floor, it will disappear between 2-4 minutes. However, when I tested this out, the item was set to invisible for lets say 132 seconds, but once it reappeared, when I pressed it again, it disappeared for 132 seconds.
The question I want to ask is if you can actually make it invisible for a different amount of time each time the item is clicked. So I don't want it to disappear for 132 seconds every time, because for the more "common" items, people can just camp them. I want it to have a random rate but I'm not sure how.
--Variable Definition
local cc = script.Parent
local candycane = game:GetService("ReplicatedStorage").candycane
local cd = cc.ClickDetector
local randomnumber = math.random(120,240)
--Main bit
cd.MouseClick:Connect(function(player)
local bp = player.Backpack
if not bp:FindFirstChild('candycane') then
candycane:Clone().Parent = bp
print(randomnumber) -- this is so I can see how long it's disappeared for.
wait(1)
cc.Handle.Transparency = 1
wait(randomnumber)
cc.Handle.Transparency = 0
else
print "already in backpack bro ,what ya doing fam, you stupid boy"
end
end)
So what I did was i defined math.random(m,n) at the start, then referred to it after I set the handle Transparency = 0
So every time I start running the script again, the time (for example) is 165, and the item is invisible for 165 seconds (after being clicked on), then it is visible again. But when i click on it again, the time it disappears for is 165 again, which I don't want to occur. I want these items to be Legendary, so the spawn rates are random and I will add in a script which will move the object.
However this only happens for one item. So the candy cane I have in this script spawns at 182 seconds (using math.random) but when it reappears, it disappears for 182 seconds, but i want it to disappear for a different number
So can someone help me? Every time I click the item, the number from math.random i get is like (another example) 182, then I want it to generate another random number, and not use 182 again.
Thanks, Tony V

3 comments
math.random(n, m) gives you a number. What you're doing is setting a variable to the value of that random number, and then reusing that. Try replacing every occurence of randomnumber with math.random(120, 240).
This is the answer. Basically replace every variable that refers to the randomn to math.random(120,240)
Thanks. i would have done that but I wnated to also know if there was another way like using math.randomseed((tick) but there's not point going into that much effort