I want to use :waitforchild so I don’t get an error because the tool has not loaded yet. Sometimes, but not always, it waits forever, even though its already there
I tried using a repeat wait() until loop but that gave the same result.
local player=game.Players.LocalPlayer
repeat wait() until player.Team
local attack=script.Attackscript
local defend=script.Defendscript
local Update=game.ReplicatedStorage.TeamUpdater
local Pack=player.Backpack
Pack:WaitForChild("Sheild")
print("waited")
I probably should have mentioned this but it is in StarterPack. I thought making the pack Variable might initialize it when it has 0 children, So I tried just doing Player.Backpack but that does not work either.
I used a Task.Spawn so It will print the children while waiting for the children and the children were there but it still said it was waiting? Is this an engine issue?
task.spawn(function()
while wait() do
print(player.Backpack:GetChildren())
end
end)
player.Backpack:WaitForChild("Sheild")
print("waited")
local Pack=player.Backpack
I have to imagine it is, this is so weird lol. Make a report on the devforum and try updating studio perhaps? Try replicating the issue in an empty baseplate.
I did as you said and stripped the code to its bare bones.
local player=game.Players.LocalPlayer
task.spawn(function()
while wait() do
print(player.Backpack:GetChildren())
end
end)
player.Backpack:WaitForChild("Shield")
print("waited")
local Pack=player.Backpack
then it started to get angry at me that backpack is not a member of player (???)
So I did this
local player=game.Players.LocalPlayer
player:WaitForChild("Backpack")
task.spawn(function()
while wait() do
print(player.Backpack:GetChildren())
end
end)
player.Backpack:WaitForChild("shield")
print("waited")
local Pack=player.Backpack
This simply says that Shield is not a member of Player.Backpack
I have never tried to use a or statement for a variable so I dont know how to troubleshoot that
local player=game.Players.LocalPlayer
repeat wait() until player.Team
local attack=script.Attackscript
local defend=script.Defendscript
local Update=game.ReplicatedStorage.TeamUpdater
local Pack=player.Backpack
local sheild = Pack["Shield"] or Pack:WaitForChild("Shield")
print("waited")
to fix this you need to wait about 1 or 2 seconds before getting the player since it is running from playerscripts. not sure why but it seems to be giving you a false player/backpack. guessing this is something on roblox end on how the player is loaded in and how the localplayer variable is referenced from playerscripts
if you run same script from say starter gui it delays enough or waits on the player loaded into the .localplayer variable
so something like
task.wait(1)
local Player = game.Players.LocalPlayer