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

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

Asked by 6 years ago
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)
0
What's the problem? oftenz 367 — 6y
0
It wont set the value of Divisional Rank tictac67 96 — 6y
0
Is filtering enabled? Is this a localscript or normal script? oftenz 367 — 6y
0
debug with prints, to see which exact part doesn't work g1o2r3d4a5n6 350 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago

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.

0
Does this allow me to change 'drank' when the player changes team? tictac67 96 — 6y
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 User#5423 17 — 6y
0
Could you add that into the script? tictac67 96 — 6y
0
I have a seperate script to team people as well tictac67 96 — 6y
View all comments (2 more)
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. User#5423 17 — 6y
0
I have no idea how to add it in. I am still learning how to script tictac67 96 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)
0
Please post this as another question instead of an answer User#5423 17 — 6y

Answer this question