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

Anybody got any help? This isn't setting the Divisional Team.

game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("IntValue")
    stats.Parent = plr
    stats.Name = "leaderstats"
    local rank = Instance.new("StringValue")
    rank.Name = "Rank"
    rank.Parent = stats
    rank.Value = "N/A"
    local drank = Instance.new("StringValue")
    drank.Name = "Divisional Rank"
    drank.Parent = stats
    drank.Value = "N/A"
if plr.Name == "tictac67" and plr.Team.Name == "Security Department" then 
        plr.leaderstats["Divisional Rank"].Value = "Overseer" 
    end
    if plr.Name == "tictac67" then
        plr.leaderstats.Rank.Value = "Overseer"
    elseif plr.Name == "tolly67p"  then
        plr.leaderstats.Rank.Value = "O5-2"
    elseif plr.Name == "MINECRAFT_LOLBUILDZ" then
        plr.leaderstats.Rank.Value = "Site Director"
    elseif plr.Name == "BrigamerGT" then
       plr.leaderstats.Rank.Value = "O5-X"
    elseif plr.Name == "JackPlaysRBYT" then
        plr.leaderstats.Rank.Value = "Class-D"
    elseif plr.Name == "consentlaw" then
        plr.leaderstats.Rank.Value = "Level-1"
    end

end)

4 comments

0

What's the problem?

0

It wont set the value of Divisional Rank

0

Is filtering enabled? Is this a localscript or normal script?

0

debug with prints, to see which exact part doesn't work

2 answers

✓ Accepted answer

When creating instances you sould setup the instance first then parent it. This is due to replicating the changes.

Secondly you have direct access to the players stats so use the variables instead of directly accessing the stats.

I think that your Divisional Rank is not being set since the player will have no team so plr.Team.Name == "Security Department" would be false in this case you should set the players team first.

As you have a lot of ranks it may be better if you use a table it will also remove a lot of your code duplication.

Lastly you would be bettter off checking the players id instead of their name as the player id will never change.

Example:-


local rankTbl = {
	-- format userid  = rank 
	[26331361] = "Overseer",
	 -- other ranks here 
}

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

	-- set players team here
	
	
	-- set stats
	if plr.UserId == 26331361 then -- check you team after it is set
		drank.Value = "Overseer"
	end
	
	-- set stats parent after setup is complete
	stats.Parent = plr
end)

I hope this helps. Please comment if you do not understand how / why this code works.

6 comments

0

Does this allow me to change 'drank' when the player changes team?

1

A Team has PlayerAdded and PlayerRemoved events which you can use to change the drank and yes you can change drank when you like

0

Could you add that into the script?

0

I have a seperate script to team people as well

0

I would like you to attempt it first even if it does not work. It may also be better to put this into the same script or use a module as well. Either way its probably better to do another question.

0

I have no idea how to add it in. I am still learning how to script

My Teaming script:

game.Players.PlayerAdded:connect(function(p) -- When a player join
	if p.Name == "tictac67" then -- Check player's name
	p.TeamColor = BrickColor.new("Medium stone grey") -- SD
elseif
		p.Name == "tolly67p" then -- Check player's name
	p.TeamColor = BrickColor.new("Cool yellow") -- E&T
elseif
		p.Name == "MINECRAFT_LOLBUILDZ" then
	p.TeamColor = BrickColor.new("Bright bluish green") -- MD
elseif
		p.Name == "JackPlaysRBYT" then
	p.TeamColor = BrickColor.new("Neon orange") -- CD
elseif
		p.Name == "consentlaw" then
	p.TeamColor = BrickColor.new("White") -- FP


end
end)

1 comment

0

Please post this as another question instead of an answer

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