Hello everyone
Why is the item given to another player when opening the case, but not to me?
it script clone item
local CD = script.Parent
local Label = CD.Parent.BillboardGui.TextLabel
local RP = game:GetService('ReplicatedStorage')
local ItemFolder = RP.ItemFolder
local OldItem = nil
local function onClicked(player)
if OldItem ~= nil then
OldItem:Destroy()
end
local ChosenItem = Label.Text
wait(0.5)
print(ChosenItem)
Label.Text = 'You got '.. ChosenItem
local item = ItemFolder:FindFirstChild(ChosenItem)
if item then
item.Parent = player.Backpack
OldItem = item
end
end
local ItemTable = {
'Katana',
'Katana'
}
local Dbg = true
local ScrollTime = 2
local ScrollInterval = 0.01
local ScrollSound = "rbxassetid://421058925"
local FinishSound = "rbxassetid://4525871712"
local OldItem = nil
script.Parent.MouseClick:Connect(function(Player)
if Dbg then
Dbg = false
for i = 1,(ScrollTime/ScrollInterval) do
if ScrollSound ~= "" then
local Sound = Instance.new("Sound", script.Parent)
Sound.Volume = 0.25
Sound.SoundId = ScrollSound
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength)
end
wait(ScrollInterval)
local ItemDisplay = ItemTable[math.random(1,#ItemTable)]
Label.Text = ItemDisplay
end
if FinishSound ~= "" then
local Sound = Instance.new("Sound", script.Parent)
Sound.Volume = 0.25
Sound.SoundId = FinishSound
Sound:Play()
game:GetService("Debris"):AddItem(Sound, Sound.TimeLength)
end
local NewItem = ItemFolder:FindFirstChild(Label.Text)
if NewItem ~= nil then
local NewItemClone = ItemFolder:FindFirstChild(Label.Text):Clone()
if OldItem ~= nil then
OldItem:Destroy()
end
OldItem = NewItemClone
NewItemClone.Parent = Player.Backpack
end
Dbg = true
end
end)
it script destroy item
--Put Your Item Name inside--
local ItemTable = {
'Katana',
'Katana'
}
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)