I made an inventory system where every time you click “equip” it fires this function on the server to update your character’s items. I’m not sure why this is causing the game to lag immensely. I feel like I just need a second pair of eyes because when I look at it I really don’t see how it could cause such an immense amount of lag…
function Refresh(player, Humanoid, Character)
Humanoid:RemoveAccessories()
wait()
local Equipment = player.EquipmentFolder
local Hat = game.ReplicatedStorage.Equipment:FindFirstChild(Equipment.Hat.Value)
if Hat and Hat ~= ("None") then
local HatCloned = Hat:Clone()
Humanoid:AddAccessory(HatCloned)
end
local Wand = game.ReplicatedStorage.Equipment:FindFirstChild(Equipment.Wand.Value)
if Wand and Wand ~= ("None") then
local WandCloned = Wand:Clone()
Humanoid:AddAccessory(WandCloned)
playAnimationFromServer(Character, 6472863718)
end
local Accessory = game.ReplicatedStorage.Equipment:FindFirstChild(Equipment.Accessory.Value)
if Accessory and Accessory ~= ("None") then
local AccessoryCloned = Accessory:Clone()
Humanoid:AddAccessory(AccessoryCloned)
end
local Hair = game.ReplicatedStorage.Equipment:FindFirstChild(Equipment.Hair.Value)
if Hair and Hair ~= ("None") and Hair ~= ("Hair01") then
local HairCloned = Hair:Clone()
Humanoid:AddAccessory(HairCloned)
end
local Robe = game.ReplicatedStorage.Equipment:FindFirstChild(Equipment.Robe.Value)
if Robe and Robe ~= ("None") then
if Character:FindFirstChild("Shirt") then
Character:FindFirstChild("Shirt"):Destroy()
end
if Character:FindFirstChild("Pants") then
Character:FindFirstChild("Pants"):Destroy()
end
local Shirt = Robe.Shirt:Clone()
local Pants = Robe.Pants:Clone()
Shirt.Parent = Humanoid.Parent
Pants.Parent = Humanoid.Parent
end
end
Please help if you have any suggestions at all. Thank you ![]()