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 3 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:

            print(player.Name.. " has joined " ..team.Name)
            local resetBridge = true
            for _,rPlr in pairs(game.Players:GetChildren()) do
                if rPlr.TeamColor == plr.TeamColor and rPlr.Name ~= plr.Name then
                    print("has teammates")
                    resetBridge = false
                end
            end
            if resetBridge == true then
                print("reset bridge")
                local path = workspace.Paths:FindFirstChild(tostring(plr.Team))
                if path then
                    print("found path")
                    path.Transparency = 0
                    path.CanCollide = true
                end
            end

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
3 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 3 years ago

You will need to store it inside of a table.

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

Answer this question