I've been trying to fix an error for a couple of hours now but it just won't work. It occurs when a player changes a team 3 times. I don't know why it's occurring tho. Can somebody please help me with this?
The Parent property of TanWebbing2 is locked, current parent: NULL, new parent StarterCharacter
Script
EntenteClassEvents.AmericanRifleManEvent.OnServerEvent:Connect(function(Player) local AmericanRifleManCharacter = EntentePowers.AmericanRifleMan:Clone() if not game.StarterPlayer:FindFirstChild("StarterCharacter") then AmericanRifleManCharacter.Name = "StarterCharacter" AmericanRifleManCharacter.Parent = game.StarterPlayer wait(.1) if TanWebbingRandom == 1 then Webbings.TanWebbing1.Parent = AmericanRifleManCharacter print('Tan 1') elseif TanWebbingRandom == 2 then Webbings.TanWebbing2.Parent = AmericanRifleManCharacter print('Tan 2') elseif TanWebbingRandom == 3 then Webbings.TanWebbing3.Parent = AmericanRifleManCharacter print('Tan 3') end else game.StarterPlayer.StarterCharacter:Destroy() AmericanRifleManCharacter.Name = "StarterCharacter" AmericanRifleManCharacter.Parent = game.StarterPlayer wait(.1) if TanWebbingRandom == 1 then Webbings.TanWebbing1.Parent = AmericanRifleManCharacter -- occurs here print('Tan 1') elseif TanWebbingRandom == 2 then Webbings.TanWebbing2.Parent = AmericanRifleManCharacter -- occurs here print('Tan 2') elseif TanWebbingRandom == 3 then Webbings.TanWebbing3.Parent = AmericanRifleManCharacter -- occurs here print('Tan 3') end end end)
Took me a while to realize that you destroyed the character.
So what I think is happening is that because you destroyed the StarterCharacter without cloning the TanWebbing, the TanWeb became destroyed as well.
Don't understand it?
Basically, when you destroyed the AmericanRifleManCharacter, you also destroyed the TabWebbing and there's no more TanWebbing to be parented. A way to fix this is to clone the TanWebbing before parenting it.
if not game.StarterPlayer:FindFirstChild("StarterCharacter") then AmericanRifleManCharacter.Name = "StarterCharacter" AmericanRifleManCharacter.Parent = game.StarterPlayer wait(.1) if TanWebbingRandom == 1 then local ClonedWeb = Webbings.TanWebbing1:Clone() -- Clones the Webbing, so now when it's parented into the StarterCharacter, there will still be a spare. ClonedWeb.Parent = AmericanRifleManCharacter print('Tan 1') elseif TanWebbingRandom == 2 then local ClonedWeb = Webbings.TanWebbing2:Clone() ClonedWeb.Parent = AmericanRifleManCharacter print('Tan 2') elseif TanWebbingRandom == 3 then local ClonedWeb = Webbings.TanWebbing3:Clone() ClonedWeb.Parent = AmericanRifleManCharacter print('Tan 3') end else game.StarterPlayer.StarterCharacter:Destroy() AmericanRifleManCharacter.Name = "StarterCharacter" AmericanRifleManCharacter.Parent = game.StarterPlayer wait(.1) if TanWebbingRandom == 1 then local ClonedWeb = Webbings.TanWebbing1:Clone() -- Clones the Webbing, so now when it's parented into the StarterCharacter, there will still be a spare. ClonedWeb.Parent = AmericanRifleManCharacter print('Tan 1') elseif TanWebbingRandom == 2 then local ClonedWeb = Webbings.TanWebbing2:Clone() ClonedWeb.Parent = AmericanRifleManCharacter print('Tan 2') elseif TanWebbingRandom == 3 then local ClonedWeb = Webbings.TanWebbing3:Clone() ClonedWeb.Parent = AmericanRifleManCharacter print('Tan 3') end end
The Parent property of TanWebbing2 is locked, current parent: NULL, new parent StarterCharacter basically means TanWebbing2 is nil or destroyed (Or garbage collected) so to prevent that error from happening, we can clone that instance before we use it so that if we need it again, there would be a spare instance for us to use.