I am in the process of making an automatic load-out system and I have come across a problem in the way the script automatically assigns a load-out when a player joins a team, I know exactly what’s causing the issue I’m just not aware on how to solve it. As you can see I have a line of code that identifies a player’s team and if they are on a certain team they will be given a load-out, problem is the function that the code lies in is only fired when the player joins. I have tried separating the code and making it’s own function resulting in failure, if you are aware of any ways to fix this issue please respond with any help you can give.
Line 102 starts the auto assign function when you join the “Hostile” team, as you can see it’s inside of “CheckClassRank”
which is only fired when the player joins as you can see here:
If you need more details in order to find a way to fix this issue please don’t be hesitant to ask.
EDIT: I want the lines between 102 and 105 fired when the player joins the “Hostile” team. Not just when the player joins.
I agree with both @VineyardVine and @Firefaul on this. Both approaches can work. @VineyardVine’s will give the correct load-out when the player respawns. @Firefaul’s will do so when the team changes. The caveat with that one though is that you need to make sure you clear whatever current load-out exists first.
Something like this:
game.Players.PlayerAdded:Connect(function(player)
-- Initial check:
local class, rank = checkClassRank(player)
-- Team changed:
player:GetPropertyChangedSignal("Team"):Connect(function()
-- Recheck:
class, rank = checkClassRank(player)
-- Redo loadout if character is in-game: (NOTE: Might be better to also check if Humanoid exists and has health > 0)
if player.Character then
clearLoadout(player)
giveLoadout(player, class, rank)
end
end)
-- Give loadout when character spawns
player.CharacterAdded:Connect(function(character)
giveLoadout(player, class, rank)
end)
end)
This does work, but the load-out doesn’t seem to actually fire… It still says “no loadout” even though the person is on the correct team and the lines work.
EDIT: the script isn’t correctly assigning the player, it’s not fault on anybody’s programming on this thread, there is now a different error. As you can see here:
Now keep in mind it DOES pass this function (if player.teamcolor… etc) it just isn’t assigning the load-out correctly…
This is what it normally looks like when you first join to have a load-out assigned:
I don’t see any problems that would relate to the teamcolor load-out that’s probably because i’m not an excellent scripter, but it should be pretty obvious if there was one. I’d also like to point out this assign on team works completely fine when you FIRST join and you’re automatically assigned on the team, however not when you switch teams.
It seems like the “id” variable you’re using as the group id represents the first variable for the in pairs statement. The first variable for an in pairs statement will always be the current position in the table. For example, id might be 1 inside of that block of code, not the group id.