----------------------------------------------------------------------
--------------------[ GUNSETUP HANDLING ]-----------------------------
----------------------------------------------------------------------



local gunSetup = script:WaitForChild("gunSetup")
function gunSetup.OnServerInvoke(Player, Vars)
	
	--------------------[ CREATING IGNORE MODELS ]--------------------------------
	
	local gunIgnore = Instance.new("Model")
	gunIgnore.Name = "gunIgnore_"..Player.Name
	gunIgnore.Parent = Vars.ignoreModel
	
	--------------------[ MODIFYING THE PLAYER ]----------------------------------
		
	Vars.Humanoid.AutoRotate = false
	
	Vars.Shoulders.Right.Part1 = nil
	Vars.Shoulders.Left.Part1 = nil
	
	local playerFolder = Instance.new("Model")
	playerFolder.Name = "playerFolder"
	playerFolder.Parent = gunIgnore
	
	local headBase = Instance.new("Part")
	headBase.Transparency = 1
	headBase.Name = "headBase"
	headBase.CanCollide = false
	headBase.FormFactor = Enum.FormFactor.Custom
	headBase.Size = V3(0.2, 0.2, 0.2)
	headBase.BottomSurface = Enum.SurfaceType.Smooth
	headBase.TopSurface = Enum.SurfaceType.Smooth
	headBase.Parent = playerFolder
		
	local headWeld = Instance.new("Weld")
	headWeld.Part0 = Vars.Torso
	headWeld.Part1 = headBase
	headWeld.C0 = CF(0, 1.5, 0)
	headWeld.Parent = Vars.Torso
	
	local headWeld2 = Instance.new("Weld")
	headWeld2.Part0 = headBase
	headWeld2.Part1 = Vars.Head
	headWeld2.Parent = headBase
		
	local animBase = Instance.new("Part")
	animBase.Transparency = 1
	animBase.Name = "animBase"
	animBase.CanCollide = false
	animBase.FormFactor = Enum.FormFactor.Custom
	animBase.Size = V3(0.2, 0.2, 0.2)
	animBase.BottomSurface = Enum.SurfaceType.Smooth
	animBase.TopSurface = Enum.SurfaceType.Smooth
	animBase.Parent = playerFolder
	
	local animWeld = Instance.new("Weld")
	animWeld.Part0 = animBase
	animWeld.Part1 = headBase
	animWeld.Parent = animBase
	
	local armBase = Instance.new("Part")
	armBase.Transparency = 1
	armBase.Name = "ArmBase"
	armBase.CanCollide = false
	armBase.FormFactor = Enum.FormFactor.Custom
	armBase.Size = V3(0.2, 0.2, 0.2)
	armBase.BottomSurface = Enum.SurfaceType.Smooth
	armBase.TopSurface = Enum.SurfaceType.Smooth
	armBase.Parent = playerFolder
	
	local ABWeld = Instance.new("Weld")
	ABWeld.Part0 = armBase
	ABWeld.Part1 = animBase
	ABWeld.Parent = armBase
		
	local LArmBase = Instance.new("Part")
	LArmBase.Transparency = 1
	LArmBase.Name = "LArmBase"
	LArmBase.CanCollide = false
	LArmBase.FormFactor = Enum.FormFactor.Custom
	LArmBase.Size = V3(0.2, 0.2, 0.2)
	LArmBase.BottomSurface = Enum.SurfaceType.Smooth
	LArmBase.TopSurface = Enum.SurfaceType.Smooth
	LArmBase.Parent = playerFolder
	
	local RArmBase = Instance.new("Part")
	RArmBase.Transparency = 1
	RArmBase.Name = "RArmBase"
	RArmBase.CanCollide = false
	RArmBase.FormFactor = Enum.FormFactor.Custom
	RArmBase.Size = V3(0.2, 0.2, 0.2)
	RArmBase.BottomSurface = Enum.SurfaceType.Smooth
	RArmBase.TopSurface = Enum.SurfaceType.Smooth
	RArmBase.Parent = playerFolder
	
	local LWeld = Instance.new("Weld")
	LWeld.Name = "LWeld"
	LWeld.Part0 = armBase
	LWeld.Part1 = LArmBase
	LWeld.C0 = Vars.armC0[1]
	LWeld.C1 = Vars.leftArmC1
	LWeld.Parent = armBase
	
	local RWeld = Instance.new("Weld")
	RWeld.Name = "RWeld"
	RWeld.Part0 = armBase
	RWeld.Part1 = RArmBase
	RWeld.C0 = Vars.armC0[2]
	RWeld.C1 = Vars.rightArmC1
	RWeld.Parent = armBase
	
	local LWeld2 = Instance.new("Weld")
	LWeld2.Name = "LWeld"
	LWeld2.Part0 = LArmBase
	LWeld2.Part1 = Vars.LArm
	LWeld2.Parent = LArmBase
	
	local RWeld2 = Instance.new("Weld")
	RWeld2.Name = "RWeld"
	RWeld2.Part0 = RArmBase
	RWeld2.Part1 = Vars.RArm
	RWeld2.Parent = RArmBase
	
	local LLegWeld = Instance.new("Weld")
	LLegWeld.Name = "LLegWeld"
	LLegWeld.Part0 = Vars.Torso
	LLegWeld.Part1 = nil
	LLegWeld.C0 = CF(-0.5, -2, 0)
	LLegWeld.Parent = Vars.Torso
	
	local RLegWeld = Instance.new("Weld")
	RLegWeld.Name = "RLegWeld"
	RLegWeld.Part0 = Vars.Torso
	RLegWeld.Part1 = nil
	RLegWeld.C0 = CF(0.5, -2, 0)
	RLegWeld.Parent = Vars.Torso
	
	for _, Tab in pairs(Vars.gunParts) do
		Tab.Obj.Anchored = false
		local Weld = Instance.new("Weld")
		Weld.Name = "mainWeld"
		Weld.Part0 = Vars.Handle
		Weld.Part1 = Tab.Obj
		Weld.C0 = Tab.Obj.weldCF.Value
		Weld.Parent = Vars.Handle
		Tab.Weld = Weld
	end
	
	return gunIgnore, playerFolder, headWeld, headWeld2, animWeld, ABWeld, LWeld, RWeld, LWeld2, RWeld2, LLegWeld, RLegWeld, Vars.gunParts
end