Group Role Halo

I am trying to make a system where if you are in the group and is above a certain rank you get a halo. The script I have is in SSS and is normal script. Can someone tell me whats wrong with it?

local moderhalo = game.ReplicatedStorage.Halos.HaloModerator
local Players = game:GetService(“Players”)

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if Player:GetRankInGroup(9744992) >= 4 then

  	local Old = Character:WaitForChild("HaloFree")
  	Old:destroy()
  	local Old2 = Character:WaitForChild("Halo5")
  	Old2:destroy()
  	local Old3 = Character:WaitForChild("Halo10")
  	Old3:destroy()
  	local Old4 = Character:WaitForChild("Halo15")
  	Old4:destroy()
  	local Old5 = Character:WaitForChild("Halo20")
  	Old5:destroy()
  	local Old6 = Character:WaitForChild("Halo25")
  	Old6:destroy()
  	local Old7 = Character:WaitForChild("PremiumHalo")
  	Old7:destroy()
  	moderhalo:Clone().Parent = Character
  end

end)
end)

Does it post an error in the console?

the game has a lot of bugs which we r trying to fix. The only thing that is “related” is this → https://gyazo.com/a71b5d85d44306440c99437d2b797953

Would seem like it isn’t finding Halo5 in your character, are you certain that part or model is there?

It’s going to yield if the player doesn’t have one of those halos, hence why you’re getting that. I would recommend putting all the names of the halos in a table, and if the player has arank of 4 or above, loop through their accessories and if their accessotry name is equal to that, remove it, are those halos Accessories or something else?

we have a system where if u have a certain lvl it gives a halo… What I want is that even if u have the lvl, I want it ot ignore it and give this halo instead of the lvl halo

Are the halos of the Accessory class?

I dont understand what u mean can u further explain

The Halos in the explorer, do they have a wizard hat or a hat icon?

yes, it does as the accessory,
if it would help I will give u the script for the lvl halo

local Level10 = game.ReplicatedStorage.Halos.Halo10
local Players = game:GetService(“Players”)

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)

  local LeaderstatsFolder = Player:WaitForChild("leaderstats")
  local Level = LeaderstatsFolder.levels

  if Level.Value == 10 then
  	Level10:Clone().Parent = Character
  else if Level.Value == 11 then
  		Level10:Clone().Parent = Character
  	else if Level.Value == 12 then
  			Level10:Clone().Parent = Character
  		else if Level.Value == 13 then
  				Level10:Clone().Parent = Character
  			else if Level.Value == 14 then
  					Level10:Clone().Parent = Character

  	
  	local Old = Character:WaitForChild("Halo5")
  	Old:destroy()

  				end
  			end
  		end
  	end
  end

end)
end)

What you could do instead is instead of wait for child use FindFirstChild to check if the halo appears, I think that should do it, so instead of checking like that do

if Character:FindFirstChild("HaloFree") then
 Character.HaloFree:Destroy()

end

It isnt the most elegant solution but that should work

I will try that, do i have to make that part for every halo?

Firstly oh god you need to improve that code, also, make a table containing all the names of the Halos

local tbl = {
    "HaloFree",
    "Halo5", --And so on
}

The code to destroy the other halos, just do this instead

for _,hat in pairs(Character.Humanoid:GetAccessories()) do
    if table.find(tbl,hat.Name) then
        hat:Destroy()
    end
end

Actually wait I’m unsure if it gives you the one sthat are parented to the character,if it errors or doesn’t work how it wants to, tell me so I can change it up

1 Like

You would have to yes unless you wanna use a lot of or statements, Embat has the better solution to this I would advise you to go with that

1 Like

Is this better?
local moderhalo = game.ReplicatedStorage.Halos.HaloModerator
local Players = game:GetService(“Players”)

local tbl = {
“HaloFree”,
“Halo5”,
“Halo10”,
“Halo15”,
“Halo20”,
“Halo25”,
“PremiumHalo”
}

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if Player:GetRankInGroup(9744992) >= 4 then
for _,hat in pairs(Character.Humanoid:GetAccessories()) do
if table.find(tbl,hat.Name) then
hat:Destroy()

  	moderhalo:Clone().Parent = Character
  		end
  	end
  end

end)
end)

Please format the code correctly, also I don’t believe so, Parent a clone of halo after the loop ends, or somehow worked as intended

I have tested and it works perfectly, just the way I want it, thx everyone who helped :slightly_smiling_face:

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

1 Like
local tbl = {
  “HaloFree”,
  “Halo5”,
  “Halo10”,
  “Halo15”,
  “Halo20”,
  “Halo25”,
  “PremiumHalo”
}

Players.PlayerAdded:Connect(function(Player)
  Player.CharacterAdded:Connect(function(Character)
    if Player:GetRankInGroup(9744992) >= 4 then
      for _,hat in pairs(Character.Humanoid:GetAccessories()) do
        if table.find(tbl,hat.Name) then
          hat:Destroy()
  	      moderhalo:Clone().Parent = Character
        end
      end
    end
  end)
end)

You want the code to look something like that properly formatted mine is a little errored because i had to indent using space instead of tab but you should get the idea, every time theres a little arrow in your studio next to a line number you should hit tab on the next line, I even think Roblox studio does that itself

1 Like

what would I have to do so that it doesnt delete when u die?