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

Why do I not spawn in the correct spawn?

On the leader board shows me that I'm on the blue team, but I spawn on the red unless I reset my self to spawn correctly on the blue spawn point. I don't want to take that extra step and reset every time I join the game. Could someone help me fix this problem? Thanks.

Group = 1234567

function Added(plyr)
    if plyr:GetRankInGroup(Group) == 255 then
        plyr.TeamColor = BrickColor.new("Toothpaste")
elseif plyr:GetRankInGroup(Group) == 254
	then plyr.TeamColor = BrickColor.new("Dark green")
elseif plyr:GetRankInGroup(Group) == 253
	then plyr.TeamColor = BrickColor.new("CGA brown")
		elseif plyr:GetRankInGroup(Group) == 1.
	then plyr.TeamColor = BrickColor.new("Crimson")
	    end
	end

game.Players.PlayerAdded:connect(Added)

1 comment

1

here youre only showing team color script, not the spawn script which where the problem is

2 answers

✓ Accepted answer

First you'll want to make sure that this is a server script. If it is a locla script, nothing will be working. Your scrip is rather correct already.

local Group = 1234567

game.Players.PlayerAdded:Connect(function(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
    plyr:LoadCharacter()
end)

This script will load the character as soon as the group is defined. I formatted it different just because, in my opinion, it is easier to read. There are 3 things you'll need to make sure of: you actually have teams with those BrickColors created, you have a neutral team, and that you have SpawnLocations for all of these. One final things you'll want to notice is the fact that I have reformatted your if and elseif statements so that the then is on the same line. As far as I know, that is how it is supposed to be, however, I don't know if it works the way you did it.

I hope this helps answer your question.

1 comment

0

Thank you so much! I have been looking for this, and you've perfected it. :)

: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 -- Kills the player
    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

0

I tried your method, but It doesn't work.

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