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