--Sigil
local tool = script.Parent
local RE = game:GetService("ReplicatedStorage")
local ArmorEvent = RE.ArmorEvent
local name = "Sigil"
local Atype = "Head"
tool.Activated:Connect(function()
ArmorEvent:FireServer(name,Atype)
end)
```
--Server Script
local RE = game:GetService(“ReplicatedStorage”)
local SS = game:GetService(“ServerStorage”)
local ArmorEvent = RE.ArmorEvent
local ArmorModel = SS.ArmorModel
local ArmorTool = SS.ArmorTool
if Atype == "Head" then
for i, v in pairs(plr.Character:GetChildren()) do
if v.Name == name then
v:Destroy()
end
for i ,v in pairs(plr.Character:GetChildren()) do
if v:IsA("Model") then
for i,y in pairs(ArmorTool:GetChildren()) do
if v:isA("Model") and y:isA("Tool") and y.Name == v.Name then
v:Destroy()
else if v:isA("Model") and y:isA("Tool") and y.Name ~= v.Name then
v:Destroy()
local clone = ArmorTool:FindFirstChild(y.Name):Clone()
clone.Parent = plr.Backpack
end
end
end
end
end
if name == "Helm" then
plr.Character:WaitForChild("Humanoid").WalkSpeed = 3
local HelmModel = SS.ArmorModel:WaitForChild("Head").Helm:Clone()
local char = plr.Character
local head = char.Head
HelmModel.Parent = char
HelmModel:SetPrimaryPartCFrame(head.CFrame)
local weld = Instance.new("WeldConstraint",HelmModel.PrimaryPart)
weld.Part0 = head
weld.Part1 = HelmModel.PrimaryPart
end
if name == "Sigil" then
plr.Character:WaitForChild("Humanoid").WalkSpeed = 13
local sigilModel = SS.ArmorModel:WaitForChild("Head").Sigil:Clone()
local char = plr.Character
local head = char.Head
sigilModel.Parent = char
sigilModel:SetPrimaryPartCFrame(head.CFrame)
local weld = Instance.new("WeldConstraint",sigilModel.PrimaryPart)
weld.Part0 = head
weld.Part1 = sigilModel.PrimaryPart
end
end
end
end)
Any help with knowing what's wrong with my clones would be appreciated
So the code you have there is going to loop through every child of the Character and for every child, since the name == “Sigil” it is going to clone that item and parent it to the character. I’m not sure exactly what you are going for but I think you probably don’t want those if statements inside the loop for every character object.
I see what you mean now, so basically my code does run, it’s just it runs too much because the for loop is going to repeat the code for the amount of stuff that is in the player character. Is there a way to make sure it doesn’t continue the loop? Or would I have to make the give-back helmet code somewhere else (for context I’m doing a tool based armor system where you can equip an item and override the equip via equipping another item(which then equips that item
) )
It is hard for me to tell what you are trying to do in the nested loops below without knowing what your objects are. I’m not sure what models you’ve put into the character and what are the children of your ArmorTool object. Also when you make a for loop inside another for loop try to use different variable names instead of reusing i and v as it will start getting real confusing.
I can show you, my setup, if that helps, though for me the main issue is just getting the helmet tool that is getting destroyed to be a tool (The way i did that is having 2 folders one for tools other for models
)
I dont get what you mean by that. My script does not have a folder called armourtool folder in the player. Instead of that I have the armor folder in server storage that i replicate and put into the client’s backpack for the armor return part of the script. I checked my server storage and i only have 2 tools in them. Sigil and helm. Though when I run the script and check the player’s backpack i noticed that though it replicated my original helmet well, it also replicated the helmet i was going to wear.(And that is my main issue)