Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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)

0
edit your question, select the code and click in the lua Icon so we can read it propperly Necro_las 412 — 4y
0
Done. lqveries 17 — 4y
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 DarkDanny04 407 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
It didn't work, I tried it in local scripts and normal scripts, what do I do? I used your entire script. lqveries 17 — 4y
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? SilentsReplacement 468 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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 :)

Answer this question