Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What's wrong with my script?

function onPlayerRespawned(newPlayer)
  if (newPlayer:IsInGroup(1144981)==true) then   ----the ID of the group that will spawn Under that Team.
   newPlayer.TeamColor = game.Teams["Malaysian Armed Forces"].TeamColor 
  end
end

function onPlayerEntered(newPlayer)
  newPlayer.Changed:connect(function (property)
    if (property == "Character") then
      onPlayerRespawned(newPlayer)
    end
  end)
 --if (_G.checkOkToBan(newPlayer.Name)) then
  --newPlayer:remove()
 --end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

2 comments

0

Why down vote you idiots.

1

Probably because you didn't post an explanation. https://scriptinghelpers.org/help/how-post-good-questions-answers

1 answer

✓ Accepted answer

The problem is that you're trying to use the Changed event, while you should be using the CharacterAdded event. This event fires every time a player respawns, or every time a character is added to the player. I'm going to use anonymous functions for my example because I find them more readable and easier to use.

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
		if plr:IsInGroup(1144981) then
			plr.TeamColor = game.Teams["Malaysian Armed Forces"].TeamColor
		end
	end)
end)

1 comment

0

Thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.