Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My bakery script doesn't work for my ROBLOX bakery place. Help?

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)

3 comments

0

edit your question, select the code and click in the lua Icon so we can read it propperly

0

Done.

0

The reason it might not delete it is that when it is equipped, it goes into the character, so if you have it equipped when it tries to delete it, it won't work

2 answers

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.

2 comments

0

It didn't work, I tried it in local scripts and normal scripts, what do I do? I used your entire script.

0

Please use normal scripts, not local. If you use local, other player's wont be able to see what you are doing. What script is it?

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 :)

This discussion is preserved as it was. New answers, comments, and votes are closed.