I’m making a game with a spectator mode. There’s a board in the lobby you click which puts you into spectator mode so you can watch other players. However, when parenting the GUI that handles spectator mode, I get this error message:
This is the code for the board that the player clicks:
local canSpectate = true
local spawns = game.Workspace.Assets.SpawnIsland.Spawns:GetChildren()
script.Parent.ClickDetector.MouseClick:Connect(function( player)
if not canSpectate then return end
local hum = player.Character:FindFirstChild("Humanoid")
if hum ~= nil then
canSpectate = false
local randomSpawn = spawns[math.random(1, #spawns)]
local speccy = game.ServerStorage.SpectateGui:Clone()
speccy.Parent = player.PlayerGui
speccy.Spectate_Script.Disabled = false
hum.Parent:MoveTo(randomSpawn.Position)
wait(1)
canSpectate = true
end
end)
I don’t believe the warning is originating from the code snipet above, could you show the full code possibly? Also this is a warning not an error and shouldn’t be catastrophic for your code, it shouldn’t interrupt your overall functionality.
Also my experience with this warning is usually when trying to set the parent of something to two different objects at the same time, so make sure that you don’t have two separate threads that are trying to make a change at the same time.
local canSpectate = true
local spawns = game.Workspace.Assets.SpawnIsland.Spawns:GetChildren()
script.Parent.ClickDetector.MouseClick:Connect(function( player)
if not canSpectate then return end
local hum = player.Character:FindFirstChild("Humanoid")
local alreadyThere = player.PlayerGui:FindFirstChild("SpectateGui")
if hum ~= nil and alreadyThere == nil then
canSpectate = false
local randomSpawn = spawns[math.random(1, #spawns)]
local speccy = game.ServerStorage.SpectateGui:Clone()
speccy.Parent = player.PlayerGui
speccy.Spectate_Script.Disabled = false
hum.Parent:MoveTo(randomSpawn.Position)
wait(1)
canSpectate = true
end
end)
It doesn’t break anything per se. The player can just click on it again and it works. For some reason, it usually only happens the first time a player spawns. But players reported this as a bug and it bothers me. Any way to fix?
I’m dumb, that was it. It was attempting to do something with the parent locally. Previously, trying to exit spectate only deleted the SpectateGui locally, and then they’d pile up in playerGui