Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-2

What's wrong with my script?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
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)
0
Why down vote you idiots. RFYassine 15 — 10y
1
Probably because you didn't post an explanation. https://scriptinghelpers.org/help/how-post-good-questions-answers Perci1 4988 — 10y

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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)
0
Thank you. RFYassine 15 — 10y
Ad

Answer this question