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

How do I get a part of this script to re run after someone joins a team?

local rankTbl = {
    -- format userid  = rank 
    [26331361] = "Overseer",
    [26332121] = "O5-2",
	[117372267] = "Site Director",
	[84185807] = "O5-X",
	[311774526] = "Class-D",
	[473500261] = "Level-1"
}
	local SD = BrickColor.new("Medium stone grey")
	local ET = BrickColor.new("Cool yellow")
	local MD = BrickColor.new("Bright bluish green")
	local CD = BrickColor.new("Bright orange")
	local FP = BrickColor.new("White")
	local CI = BrickColor.new("Really black")
	local CE = BrickColor.new("Black")
	local DEA = BrickColor.new("Pastel light blue")
	local DoR = BrickColor.new("Mulberry")
	local EC = BrickColor.new("Grime")
	local IA = BrickColor.new("Crimson")
	local ISD = BrickColor.new("Dusty Rose")
	local MAD = BrickColor.new("Deep orange")
	local MTF = BrickColor.new("Storm blue")
	local ScD = BrickColor.new("Deep blue")
game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"

    local rank = Instance.new("StringValue")
    rank.Name = "Rank"
    rank.Value = rankTbl[plr.UserId]  or "N/A" -- if rankTbl[plr.UserId] is nil pass 'N/A'
    rank.Parent = stats -- safe to do since stats has a nil parent ie not ingame

    local drank = Instance.new("StringValue")
    drank.Name = "Divisional Rank"
    drank.Value = "N/A"
    drank.Parent = stats

    -- When a player join
	if plr.Name == "tictac67" then -- Check player's name
	plr.TeamColor = SD
	elseif
		plr.Name == "tolly67p" then -- Check player's name
	plr.TeamColor = ET
	elseif
		plr.Name == "MINECRAFT_LOLBUILDZ" then
	plr.TeamColor = MD
	elseif
		plr.Name == "JackPlaysRBYT" then
	plr.TeamColor = CD
	elseif
		plr.Name == "consentlaw" then
	plr.TeamColor = FP


end
-- Want this to refresh --
	if plr.UserId == 26331361 then
        drank.Value = "Overseer"
	elseif plr.UserId == 26332121 and plr.Team.Name == "Engineering and Technical" then
		drank.Value = "Director"
	end
    
-- Refresh stop here --

    -- set stats parent after setup is complete
    stats.Parent = plr
end)


5 comments

0

maybe like game.Players.PlayerAdded:Connect(function(plr) end) ?

0

I already have that. That is just when the player joins

0

Player:GetPropertyChangedSignal("Team"):Connect() ...

0

Your comment got cut off or did you mean to put ...

0

It does not work

1 answer

So, you want to add this at the start so the script will check whenever a player joins a team.

if game.Teams.["TEAM HERE","TEAM HERE","etc"].PlayerAdded:connect (function(player) then
--SCRIPT HERE
end)

After then will be the rest of the script. So, game.Teams refers to the teams folder in game. Then .["Mobile Task Force"]PlayerAdded:connect (function(player) end) refers to the team and when a player is added. You need an end due to the function.

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