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

Repeat wait until an object exists?

Asked by
OniiCh_n 410 Moderation Voter
10 years ago

I want multiple instances to be created ONLY when an object is created in another script. This is the code I came up with.

game.Players.PlayerAdded:connect(function(plr)
    repeat wait() until not plr.storage
            local item = Instance.new("BoolValue", plr.storage)
    end)

I know it's wrong.

The storage object is a Backpack placed inside the Player. Inside it contains a lot of BoolValues for future reference. I want the BoolValues to be created in a separate script just for the sake of organization on my part.

0
Why not just do: if something ~= nil then systematicaddict 295 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

The problem is that you are waiting until that storage doesn't exist. This is proper logic:

game.Players.PlayerAdded:connect(function(plr)
    repeat wait() until plr:FindFirstChild("storage")
            local item = Instance.new("BoolValue", plr.storage)
    end)
Ad
Log in to vote
0
Answered by
digpoe 65 Badge of Merit
10 years ago

A better suggestion than what zars15 suggested is this;

game.Players.PlayerAdded:connect(function(plr)
    local storage = plr:WaitForChild("storage")
    local item = Instance.new("BoolValue", storage)
end)

Look at the wiki - WaitForChild

Answer this question