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

How to detect a player's previous team?

Asked by 4 years ago

I'm making a pixel art game where you can disable other players from coming to where you draw. What I'm trying to do is detect a player's previous team, so that I can make their bridge able to collide again if they have no teammates. Here's a bit of my script:

01print(player.Name.. " has joined " ..team.Name)
02local resetBridge = true
03for _,rPlr in pairs(game.Players:GetChildren()) do
04    if rPlr.TeamColor == plr.TeamColor and rPlr.Name ~= plr.Name then
05        print("has teammates")
06        resetBridge = false
07    end
08end
09if resetBridge == true then
10    print("reset bridge")
11    local path = workspace.Paths:FindFirstChild(tostring(plr.Team))
12    if path then
13        print("found path")
14        path.Transparency = 0
15        path.CanCollide = true
16    end
17end

It prints when a player joins a team, but the problem is that it only picks up the new team when it tries to make the path able to collide.

2 answers

Log in to vote
1
Answered by
A_Mp5 222 Moderation Voter
4 years ago

it's either you store it in a data store or store it in something else, like an object value or string value,

so every time they change a team, it's stored, and when they join the game, the team they are in is stored.

I got no scripts tho

Ad
Log in to vote
0
Answered by 4 years ago

You will need to store it inside of a table.

1local Teams = {}
2local Player = game.Players.LocalPlayer
3Player:GetPropertyChangedSignal("Team"):Connect(function()
4table.insert(Teams, Player.Team)
5print(Player.Name.." changed team to "..Player.Team)
6end)

Answer this question