Hello:)
How do I make the old item disappear in Roblox Studio when opening the next case? robloxapp-20200905-2103202.wmv (7.4 MB)
‘’’
–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())
--choosing 1 item every 0.1 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)
‘’’
You can remove instances by calling :Destroy() on them. That will also disconnect any events associated with it and recursively destroy any descendants of that object. If you have any variables referencing the thing you’re destroying also make sure to set them to nil so that it is freed from memory.
local Brick = workspace:FindFirstChild("Brick") -- :FindFirstChild() means it will find the first part called Brick in the workspace and assign it as whatever you set the local name to
function onClicked() --functions when the part is clicked
Brick:Destroy() -- self-explanatory
end
script.Parent.ClickDetector.MouseClick:connect(onClicked) --sets a name for the click function
If you put that script and a clickdetector inside of a part, then name something “Brick”, whenever you are in game and you click the part it will delete the object named Brick.
Tip with the dev forums, include as may videos or gifs as possible (use a screen recorder like ShareX for windows, Kap for mac) then upload onto imgur or streamable they are the easiest to understand a problem from. Moreover, use three backticks ``` to format code like such, doing both of these things will help you get a response much quicker by interested devs:
–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())
--choosing 1 item every 0.1 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)