Hello everyone
I’m currently creating my own roblox game, and i can’t write a script to make the old item disappear in roblox Studio when opening the second case, and a new one has appeared. Help me please:)
Untitled Game - Roblox Studio 04.09.2020 23_59_24
1920×1017 683 KB
–Put Your Item Name inside–
local ItemTable = {
‘Electro’,
‘Electro’,
‘SunGodPowers’,
‘SunGodPowers’
}
local CD = script.Parent.ClickDetector
local Label = script.Parent.BillboardGui.TextLabel
–Debounce Mechanism–
local Debounce = false
local Stop = false
–Put your Item inside a folder in Replicated Storage–
local RP = game:GetService(‘ReplicatedStorage’)
local itemFolder = RP.itemFolder
–Click Function–
local function onClicked(player)
--Checking--
print('Clicked')
--if debounce = true--
if Debounce then print('Debounce Active') return end
Debounce = true
--Stop = true if the function is running--
spawn(function()
wait(5)
Stop = true
end)
math.randomseed(tick)
--choos 1 item every 0.5 seconds until stop = true--
repeat
local ItemDisplay = ItemTable[math.random(1,#ItemTable)]
Label.Text = ItemDisplay
wait(0.1)
until Stop == true
--chosen item result--
local ChosenItem = Label.Text
wait(0.5)
print(ChosenItem)
Label.Text = 'You got '.. ChosenItem
--finding the item in the folder--
if ItemFolder:FindFirstChild(ChosenItem) then
local cloned = ItemFolder[ChosenItem]:Clone()
cloned.Parent = player.Backpack
end
--stop the debounce--
Stop = false
wait(1)
Debounce = false
end
–Run the function when you left click–
CD.MouseClick:Connect(onClicked)