Okay, so: This is the code:
local donut = game.ReplicatedStorage.Donut:Clone() local baking = game.ReplicatedStorage.Baking:Clone() script.Parent.ClickDetector.MouseClick:Connect(function(Player) Player.Backpack:FindFirstChild("Donut Tray") game.ReplicatedStorage.Baking:Clone() baking.Parent = Player.PlayerGui wait(20) game.ReplicatedStorage.Donut:Clone() donut.Parent = Player.Backpack Player.Backpack["Donut Tray"]:Destroy() end)
And it says "Donut Tray" is not a valid member of Backpack, but it is, and I really don't understand it, please, any help?
(This is what I want it to do: I want it so you click on it, making it so it bakes it, and it puts a GUI of a timer of how long until you get your item, and then it gives you the Donut. But, for some reason, it doesn't let me destroy the Donut Tray.)
(I fixed it! Ty guys! <3)
It is actually saying that Donut Tray
is not a valid member of the backpack, meaning that it doesn't exist or you didn't define a variable for player and backpack or the backpack just hasn't loaded in the player.. A single small mistake can cause a whole script to error, remember!
local donut = game.ReplicatedStorage.Donut:Clone() local baking = game.ReplicatedStorage.Baking:Clone() script.Parent.ClickDetector.MouseClick:Connect(function(Player) if Player:WaitForChild("Backpack"):FindFirstChild("Donut Tray") then -- Waits for the backpack to load and ensures that Donut Tray exists in the backpack.. game.ReplicatedStorage.baking:Clone() baking.Parent = Player.PlayerGui wait(20) game.ReplicatedStorage.Donut:Clone() donut.Parent = Player.Backpack Player.Backpack:FindFirstChild("Donut Tray"):Destroy() end end)
Assuming that this is a local script. If this doesn't work, please show the full script and let me know if there are any errors.
local donut = game.ReplicatedStorage.Donut:Clone() local baking = game.ReplicatedStorage.Baking:Clone() script.Parent.ClickDetector.MouseClick:Connect(function(Player) local Back = Player.Backpack:FindFirstChild("Donut Tray") local CharTool = Player.Character:FindFirstChild("Donut Tray") if Back then game.ReplicatedStorage.Baking:Clone() baking.Parent = Player.PlayerGui wait(20) donut.Parent = Player.Backpack if Back then Back:Destroy() end if CharTool then CharTool:Destroy() end end end)
Like Silents said, this must be a normal script inside of the part that you click.
What this does is when you click it, it checks if the Donut tray is in the backpack, since you can not click clickdetectors with a tool out, you don't need to worry about checking if it's in their character.
It then runs through the GUI, waits 20 seconds, and then checks again if it is in the backpack or if it is in the character. No matter where it is, it will be destroyed and the donut tool will be given.
Hope this helps, and I wish you good luck on your bakery :)