basically im trying to use a table and check if a player is part of any of the groups inside said table and then do something with it. thing is i’m having trouble with doing the first part
here code:
local groupservice = game:GetService("GroupService")
local branchId = {
17155406 == "Hæren",
17155498 == "Sjøforsvaret",
17155580 == "Luftforsvaret",
17155709 == "Forsvarets Spesialstyrker"
}
local divId = {
32455961 == "Forsvarets Militærpoliti",
32456080 == "Brigade Nord",
32456166 == "Hærens Treningskommando",
32456169 == "Sjøforsvarets Flåte",
32456174 == "Kystvakten",
32456179 == "Minedykkerkommandoen",
32456180 == "Sjøforsvaret Treningskommando",
32457860 == "132 Luftving",
32457867 == "Maritim Helikopterving",
32457873 == "Luftforsvaret Treningskommando",
17155941 == "Forsvarets Spesialkommando",
17156029 == "Marinejegerkommandoen",
17162072 == "Krigsskolen"
}
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("IntValue",plr)
ls.Name = "leaderstats"
ls.Value = nil
local pG = Instance.new("StringValue",ls)
pG.Name = "Paygrade"
local bRank = Instance.new("StringValue",ls)
bRank.Name = "B. Rank"
local div = Instance.new("StringValue",ls)
div.Name = "Division"
if plr:GetRankInGroup(17152005) > 0 then
pG.Value = plr:GetRoleInGroup(17152005)
end
for i,v in pairs(branchId) do
if plr:GetRankInGroup(v) > 0 then
end
end
end)
look at the bottom part, that’s where i am right now.
== basically means you are declaring that Something is a Certain thing, which In this case you are saying number == string, which is false, Instead Surround the numbers with Brackets [], and Replicate == with =
So It should be [number] = string, instead of number == string, this will make the number the Index (or the name of the Table Item that holds a Value, next thing would be to change the for loop to work in this way:
for i,v in pairs(branchId) do
-- i means index
-- v means value
-- apply them as such
if plr:GetRankInGroup(i) > 0 then
-- code
end
end
If you’re trying to see what someone’s branch and division is and do something based on those (but I assume those 2 are independent? Meaning every branch has the same divisions and they should all do the same based on that) you COULD do
function Hæren() -- This is remarkably irresponsible as a name. I'd use one without the special characters. See divId table for an example.
-- Do Something
end
local branchId = {
17155406 = Hæren,
-- ...
}
function ForsvaretsMilitaerpoliti()
-- Do Something
end
local divId= {
32455961 = ForsvaretsMilitaerpoliti,
-- ...
}
for id,func in branchId do
if player:IsInGroup(id) then
func()
end
end
for id,func in divId do
if player:IsInGroup(id) then
func()
end
end