Hello everyone,
I have a Suitcase in my Inventory/Backpack and when i Click into the Dresser i want the Suitcase to get Delted out of my Inventory. In addition some items appear in the Dresser. Thats works fine but the Suitcase isnt deleted sadly. Whats wrong? Can anybody help?
Here is the Script:
local suitcaseName = "Suitcase"
local Click = script.Parent.ClickDetector
local function onButtonPress(player)
-- Check if the player has the "Suitcase" item in their inventory
local character = player.Character
local backpack = player:FindFirstChild("Backpack")
if character and backpack then
local suitcase = backpack:FindFirstChild(suitcaseName) or character:FindFirstChild(suitcaseName)
if suitcase then
-- If the suitcase is found, delete it
suitcase:Destroy()
print("Suitcase deleted from player's inventory.")
-- Optionally, you can add additional logic here
-- For example, play a sound or perform other actions
else
print("Suitcase not found in player's inventory.")
end
end
end
Click.MouseClick:Connect(function()
-- Get the player who clicked the button
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent.Parent)
if player then
-- Call the function to delete the "Suitcase" item for the pressing player
onButtonPress(player)
end
-- Additional functionality for the button click
script.Parent.Parent.PartPart.PutSuitcaseBack.Enabled = true
script.Parent.Parent.PartPart.WardrobeFilled.ContentNotTransparent.Enabled = true
end)
^ Filled Dresser
^The Part thats Clicked
Thank you guys for your Hekp alrerady <3