I want to make so you either, respawn so you actually get to the right spawn, or the script loads faster so you can be placed in a team before you get spawned.
There is no issue, I have checked everything, my teams & the spawns.
Note: I’m new to scripting, so if someone could show me how you could make anything like this it would be very appreciated.
When I respawn you get spawned on the right place, so it’s only when you spawn for the first time.
I have auto assignable off, and the neutral off, so that is not the problem.
local groups = {
[9667328] = "Training & Doctrine Command",
[9659028] = "Personnel",
}
game.Players.PlayerAdded:Connect(function(player)
for ids,team in pairs(groups) do
if player:IsInGroup(ids) then
player.Team = game.Teams[team]
end
end
end)
Greetings, it is not a problem of how fast the code is ran, instead the first time the player spawns, he gets teamed but not refreshed, which instead happens whenever he resets, so I would suggest adding player:LoadCharacter() right after player.Team = game.Teams[team]
Exactly, GetRankInGroup returns a number from 0 to 255, 0 means he isn’t in the group, so you can do:
game.Players.PlayerAdded:Connect(function(player)
for ids,team in pairs(groups) do
local rankInGroup = player:GetRankInGroup(ids)
if rankInGroup > 250 then
player.Team = game.Teams[team] --Change this to the specific team
elseif rankInGroup > 0 then
player.Team = game.Teams[team]
end
end
end)
Again, sorry. I belive I waste your time now but it didn’t work, did I do something wrong?
[9667328] = "Training & Doctrine Command",
[9659028] = "Personnel",
}
game.Players.PlayerAdded:Connect(function(player)
for ids,team in pairs(groups) do
local rankInGroup = player:GetRankInGroup(ids)
if rankInGroup > 250 then
player.Team = game.Teams["Army Staff"] --Change this to the specific team
elseif rankInGroup > 0 then
player.Team = game.Teams["Personnel"]
player:LoadCharacter()
end
end
end)```
You forgot to put player:LoadCharacter() to the first case of the if statement,
local groups = {
[9667328] = "Training & Doctrine Command",
[9659028] = "Personnel",
}
game.Players.PlayerAdded:Connect(function(player)
for ids,team in pairs(groups) do
local rankInGroup = player:GetRankInGroup(ids)
if rankInGroup > 250 then
player.Team = game.Teams["Army Staff"] --Change this to the specific team
player:LoadCharacter()
elseif rankInGroup > 0 then
player.Team = game.Teams["Personnel"]
player:LoadCharacter()
end
end
end)
Well, if we now say I want to change it in TRADOC, then it will be the same there? Or is there a way to like only have IsInGroup with TRADOC (Training & Doctrine Command) and GetRankInGroup with Personnel.
Since you retreive the player rank with local rankInGroup = player:GetRankInGroup(ids)I suggest you to keep working on it without going with IsInGroup(), as the rank gets saved in that variable and it’s a bit faster and generally better for the game to retreive that instead of doing a new/multiple requests, so you would keep going with the if/elseif statements.