:GetRankInGroup() is a yielding function which means it will stop the script until it gets the result, if you use it 4 times in this case then what is possible is that your character loads before you change the team color, to fix this: first you should use :GetRankInGroup() only once, it will save you time.
function Added(plyr)
local rank = plyr:GetRankInGroup(Group)
if rank == 255 then
plyr.TeamColor = BrickColor.new("Toothpaste")
elseif rank == 254
then plyr.TeamColor = BrickColor.new("Dark green")
elseif rank == 253
then plyr.TeamColor = BrickColor.new("CGA brown")
elseif rank == 1.
then plyr.TeamColor = BrickColor.new("Crimson")
end
end
But there still could be chance for the character to spawn before the function finishes. Another fix for that is to manually create character loading and load the character when you need (in this case after the function finishes) but you would have to do that every time the character dies.
Another solution which would be probably the easiest is to kill the player after finishing the function:
function Added(plyr)
local rank = plyr:GetRankInGroup(Group)
if rank == 255 then
plyr.TeamColor = BrickColor.new("Toothpaste")
elseif rank == 254
then plyr.TeamColor = BrickColor.new("Dark green")
elseif rank == 253
then plyr.TeamColor = BrickColor.new("CGA brown")
elseif rank == 1
then plyr.TeamColor = BrickColor.new("Crimson")
end
player.Character.Humanoid.Health = 0
end
This will kill it after loading the teams which will then spawn the character where you need.
Here also a tip:
You should be using local unless you are using getfenv (which i guess you don't even know what is). It is better practice to do it so:
local Group = 1234567
instead of
Group = 1234567
and
local function Added(plyr)
local rank = plyr:GetRankInGroup(Group)
if rank == 255 then
plyr.TeamColor = BrickColor.new("Toothpaste")
elseif rank == 254
then plyr.TeamColor = BrickColor.new("Dark green")
elseif rank == 253
then plyr.TeamColor = BrickColor.new("CGA brown")
elseif rank == 1
then plyr.TeamColor = BrickColor.new("Crimson")
end
end
instead of
function Added(plyr)
local rank = plyr:GetRankInGroup(Group)
if rank == 255 then
plyr.TeamColor = BrickColor.new("Toothpaste")
elseif rank == 254
then plyr.TeamColor = BrickColor.new("Dark green")
elseif rank == 253
then plyr.TeamColor = BrickColor.new("CGA brown")
elseif rank == 1
then plyr.TeamColor = BrickColor.new("Crimson")
end
end
1 comment
here youre only showing team color script, not the spawn script which where the problem is