So I have this script that gives a belt, but it does not remove the other belts, any help?
local Fendi = game.ServerStorage.Belts.Fendi
local re = Instance.new("RemoteEvent",game.ReplicatedStorage.BackpackEvents)
re.Name = "GiveFendi"
re.OnServerEvent:Connect(function(Player)
local character = Player.Character
for i, obj in pairs(character:GetChildren()) do
if obj.Name == "LouisVuitton" or obj.Name == "Versace" or obj.Name == "Gucci" or obj.Name == "Fendi" then
obj:Destroy()
end
end
Player:WaitForChild("leaderstats").Belts.Value = 1
print("FENDIII")
local newRadio = Fendi:Clone()
newRadio.Parent = character
newRadio.CFrame = character:WaitForChild("LowerTorso").CFrame * CFrame.Angles(0,3.14,6) -- or Torso if you use R6
local weld = Instance.new("Weld")
weld.Part0 = newRadio
weld.Part1 = character:WaitForChild("LowerTorso")
weld.C0 =newRadio.CFrame:inverse()
weld.C1 = character:WaitForChild("LowerTorso").CFrame:inverse()
weld.Parent = newRadio
end)
It may be better to use :IsA() to find the belts in the character as opposed to just the names. I don’t know if this would solve your problem or not but it would most likely be more efficient.
:IsA() is used for instances such as Models, Parts, UnionOperations etc. You can’t use it for specific names.
I assume the belt is a Union / MeshPart and I know that there could possibly be another meshpart inside the character so using :IsA(‘MeshPart’) is not going to work because there is the possibility of other mesh parts inside the character that would be returned. Using names is a better way to do it.
I don’t see any reason why the loop you are using to destroy the object shouldn’t be working. Could you try putting a print statement to see if it prints? I really don’t know how your game is structured so it’s hard to tell. Maybe you didn’t spell the belt correctly?
Try doing it like this and let me know what prints:
print(0)
for i, obj in pairs(character:GetChildren()) do
if obj.Name == "LouisVuitton" or obj.Name == "Versace" or obj.Name == "Gucci" or obj.Name == "Fendi" then
print(1)
obj:Destroy()
else
print(obj.Name) -- check if you misspelled the name of the belt
end
end