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

Cant find the location of the tool, can anyone help?

Asked by 3 years ago

Ok, so basically I found the backpack in this script but it turns out I cant find the tool inside of the backpack.

Error: Tray is not a valid member of Backpack"

I did put it in starter pack so it'll get transferred to the player's backpack, however it said that the tool isn't a member of backpack, when it is.

I don't understand what is wrong, can anyone give feedback/help?

Code:

    local ProximityPromt = script.Parent.ProximityPrompt
    --- Pizza Models
    local Pizza1 = game.Workspace.Pizza1
    local Pizza2 = game.Workspace.Pizza2
    local Pizza3 = game.Workspace.Pizza3
local Pizza4 = game.Workspace.Pizza4

game.Players.PlayerAdded:connect(function(player)
    local Backpack = player.Backpack
    local Tray = Backpack.Tray
end)

ProximityPromt.Triggered:Connect(function()
    ProximityPromt.ActionText = "Cook"
        if ProximityPromt.ActionText == "Cook" then
                    Pizza1.Transparency = 0
                    ProximityPromt.Enabled = false
        wait(15)
        ProximityPromt.Enabled = true
        ProximityPromt.ActionText = "Pick Up"
        ProximityPromt.Triggered:Connect(function()
            Pizza1.Transparency = 1
            wait(5)
            ProximityPromt.ActionText = "Cooldown..."   
        end)


    end
end)

1 answer

Log in to vote
1
Answered by 3 years ago

The 'event' ran before the 'Tray' can load in. I suggest using ':WaitForChild()' to make up for it. By the way, I'm kinda rep-hungry... Anyways. Happy scripting!

0
Oh ok, Thanks! usmaniusmangamer15 9 — 3y
Ad

Answer this question