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
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
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
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
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
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()
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