the line that clones the model (31) does so 5 times and only that line and everything after, how do i fix this?
local Services = {
["StarterGUI"] = game:GetService("StarterGui"),
["UserInputService"] = game:GetService("UserInputService"),
["ContextActionService"] = game:GetService("ContextActionService"),
["Debris"] = game:GetService("Debris"),
["TweenService"] = game:GetService("TweenService"),
["ReplicatedStorage"] = game:GetService("ReplicatedStorage"),
["ServerStorage"] = game:GetService("ServerStorage"),
["CollectionService"] = game:GetService("CollectionService")
}
local remote = Services.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("StateMachineRemotes"):WaitForChild("MovesetSwitchEvent")
remote.OnServerEvent:Connect(function(player: Player, ...: any)
local char = player.Character
local hum = char:FindFirstChildOfClass("Humanoid")
local PlayerSpecial = hum:GetAttribute("Special")
local HasModel = hum:GetAttribute("SpecialHasModel")
if hum:GetAttribute("CurrentMoveset") == "Weapon" then
hum:SetAttribute("CurrentMoveset", "Special")
for i,SpecialFolder in pairs(Services.ServerStorage:WaitForChild("Movesets"):WaitForChild("SpecialMovesets"):GetChildren()) do
if SpecialFolder:IsA("Folder") and SpecialFolder.Name == PlayerSpecial then
for _,Special in pairs(SpecialFolder:GetChildren()) do
if Special:IsA("ModuleScript") then
local SpecialSkill = Special:Clone()
SpecialSkill.Parent = player.Backpack.SkillsFolder.SpecialSkillsFolder
if HasModel == true then
local Model = SpecialFolder:WaitForChild("Model").Value:Clone()
Model:SetAttribute("Player", player.Name)
Model.Parent = workspace.FX.Models
print(Model.Parent:GetChildren())
for i, v in pairs(char:GetDescendants()) do
if v:IsA("Part") and v.Name == Model.PlayerJoint:GetAttribute("AttachTo") then
Model.PlayerJoint.Part0 = v
end
end
for i, v in pairs(Model:GetDescendants()) do
if v.Name ~= "HumanoidRootPart" then
if v:IsA("Part") or v:IsA("Decal") or v:IsA("MeshPart") then
Services.TweenService:Create(v, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Transparency = 0}):Play()
end
end
end
Services.TweenService:Create(Model.PlayerJoint, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {C0 = Model.PlayerJoint:GetAttribute("C0Aim")}):Play()
end
end
end
end
end
else
hum:SetAttribute("CurrentMoveset", "Weapon")
for _,SpecialMovesFolder in pairs(Services.ServerStorage:WaitForChild("Movesets"):WaitForChild("SpecialMovesets"):GetChildren()) do
if SpecialMovesFolder:IsA("Folder") and SpecialMovesFolder.Name == PlayerSpecial then
for _, ServerSpecialSkill in pairs(SpecialMovesFolder:GetChildren()) do
for _,SpecialSkill in pairs(player.Backpack.SkillsFolder.SpecialSkillsFolder:GetChildren()) do
if SpecialSkill.Name == ServerSpecialSkill.Name then
SpecialSkill:Destroy()
if HasModel == true then
local specialModelName = SpecialMovesFolder.Model.Value.Name
for _,SpecialModel in pairs(workspace.FX.Models:GetChildren()) do
if SpecialModel.Name == specialModelName and SpecialModel:GetAttribute("Player") == player.Name then
SpecialModel:Destroy()
end
end
end
end
end
end
end
end
end
player.PlayerGui.PlayerHUDGUI.SkillsFrame.InfoFrame.InfoText.Text = hum:GetAttribute("CurrentMoveset")
end)