I’m trying to place all players on the “Killers” team into a folder, and then remove them from that folder if they switch teams (I’ll be using this folder in further scripts to allow them to only affect members of the “Killers” team, so if you know an easier method to doing this then please let me know)
The problem is, in the line of code in which I change the character’s parent to the folder (line 7) there is an error I get which says “Attempt to index nil with parent”. Even though this line itself works just fine, the rest of the code is stopped from working because of the error (this stops the script from removing the players from the killers folder once they change teams).
I haven’t been able to find a solution yet, although I haven’t tried all of my options.
Here’s the code I’m currently working with:
local teamKiller = game:GetService("Teams")["Killer"]
local teamRunner = game:GetService("Teams")["Runner"]
game:GetService("RunService").Heartbeat:Connect(function(dt)
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
print("test")
if (player.TeamColor == teamKiller.TeamColor) then
player.Character.Parent = game.Workspace.KillersList
if player.TeamColor ~= teamKiller.TeamColor then player.Character.Parent = game.Workspace
end
end
end
end)