--pose data
poses = {
	equip = {
		[1] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Sine, easingdirs.In},
			hw = {CFrame.new(-0.0665130615, 0, -0.0558013916, 0.764023483, -0.133021921, 0.631326377, 0.0301536229, 0.984807849, 0.17100969, -0.644483387, -0.111618645, 0.756427288), easingstyles.Sine, easingdirs.In},
			gw = {CFrame.new(-0.459022522, 0.0749015808, 0.17483139, 2.98023224e-08, 0.999999404, 5.58793545e-08, 0.939692438, -2.68220901e-07, -0.342020184, -0.342019945, 0, -0.939691842), easingstyles.Sine, easingdirs.InOut},
			tw = {CFrame.new(0, 0, 0, 0.642787516, 0, -0.766044497, 0, 1, 0, 0.766044497, 0, 0.642787516), easingstyles.Sine, easingdirs.In},
			raw = {CFrame.new(0.832485199, -0.995883942, -0.72026825, 0.986079514, -0.00105690956, 0.166270182, 0.166003779, -0.0506849214, -0.984821558, 0.00946819782, 0.998714149, -0.0498039126), easingstyles.Sine, easingdirs.InOut},
			law = {CFrame.new(0.0268783569, -1.61439657, -2.11585999, -0.222152725, -0.453005493, 0.863385201, 0.810823023, -0.57762152, -0.0944410712, 0.541492224, 0.67907244, 0.495627582), easingstyles.Sine, easingdirs.InOut},
		},
		[2] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(0.0999984741, 0.104999542, 0.0449981689, 0.99999404, -1.41561031e-06, -1.00024045e-06, -1.41561031e-06, 0.999997914, -2.98023224e-08, -1.00024045e-06, -2.98023224e-08, 0.999999702), easingstyles.Linear, easingdirs.InOut},
			hw = {CFrame.new(-0.0665130615, 0, -0.0558013916, 0.764023662, -0.133021936, 0.631326437, 0.0301536229, 0.984807849, 0.17100969, -0.644483507, -0.111618653, 0.756427407), easingstyles.Linear, easingdirs.InOut},
			gw = {CFrame.new(-0.459018707, -0.325099945, 0.174833298, 2.98023224e-08, 0.999998987, 1.04308128e-07, 0.939692378, -3.87430191e-07, -0.342020214, -0.342019826, 1.49011612e-08, -0.939691484), easingstyles.Linear, easingdirs.InOut},
			raw = {CFrame.new(0.810245514, -1.00666809, -0.31388092, 0.978280365, 2.5331974e-06, 0.2072853, 0.206869617, -0.0633132458, -0.976317585, 0.0131213665, 0.997993708, -0.0619386435), easingstyles.Sine, easingdirs.InOut},
			law = {CFrame.new(0.0326385498, -1.61523056, -2.11762619, -0.256376684, -0.429218709, 0.866049647, 0.79393369, -0.604562879, -0.0645961761, 0.55130744, 0.671025276, 0.495767117), easingstyles.Sine, easingdirs.InOut},
		},
		[3] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Back, easingdirs.Out},
			hw = {CFrame.new(0, 0, 0, 0.642787635, 0, 0.766044438, 0, 1, 0, -0.766044438, 0, 0.642787635), easingstyles.Sine, easingdirs.Out},
			gw = {CFrame.new(-0.209030151, -1.02510452, -0.225169182, 9.54675698e-08, 0.99999994, 8.86497986e-10, 0.939692557, -1.49011612e-07, -0.342020124, -0.342020124, 3.348487e-08, -0.939692557), easingstyles.Sine, easingdirs.Out},
			raw = {CFrame.new(0.659713745, -1.45935869, 0.354370117, 0.99999994, -2.98023224e-08, 3.35276127e-08, 3.53902578e-08, -3.21306288e-08, -0.999999881, -2.98023224e-08, 1, -3.0035153e-08), easingstyles.Sine, easingdirs.Out},
			law = {CFrame.new(-0.000568389893, -1.6040411, -2.10723114, -0.0793336332, -0.53615725, 0.840381742, 0.862421989, -0.459712416, -0.211878672, 0.499934286, 0.707954705, 0.498864472), easingstyles.Sine, easingdirs.Out},
		}
	},
	shoot = {
		[1] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(0.0999984741, 0.104999542, 0.0449981689, 0.99999404, -1.41561031e-06, -1.00024045e-06, -1.41561031e-06, 0.999997914, -2.98023224e-08, -1.00024045e-06, -2.98023224e-08, 0.999999702), easingstyles.Back, easingdirs.Out},
			hw = {CFrame.new(0, 0, 0, 0.642787635, 0, 0.766044438, 0, 1, 0, -0.766044438, 0, 0.642787635), easingstyles.Back, easingdirs.Out},
			gw = {CFrame.new(-0.209030151, -1.02510452, -0.225169182, 9.54675698e-08, 0.99999994, 8.86497986e-10, 0.939692557, -1.49011612e-07, -0.342020124, -0.342020124, 3.348487e-08, -0.939692557), easingstyles.Back, easingdirs.Out},
			raw = {CFrame.new(0.659713745, -1.45935869, 0.354370117, 0.99999994, -2.98023224e-08, 3.35276127e-08, 3.53902578e-08, -3.21306288e-08, -0.999999881, -2.98023224e-08, 1, -3.0035153e-08), easingstyles.Back, easingdirs.Out},
			law = {CFrame.new(-0.000568389893, -1.6040411, -2.10723114, -0.0793336332, -0.53615725, 0.840381742, 0.862421989, -0.459712416, -0.211878672, 0.499934286, 0.707954705, 0.498864472), easingstyles.Back, easingdirs.Out},
		},
		[2] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Back, easingdirs.Out},
			hw = {CFrame.new(0, 0, 0, 0.642787635, 0, 0.766044438, 0, 1, 0, -0.766044438, 0, 0.642787635), easingstyles.Back, easingdirs.Out},
			gw = {CFrame.new(-0.209030151, -1.02510452, -0.225169182, 9.54675698e-08, 0.99999994, 8.86497986e-10, 0.939692557, -1.49011612e-07, -0.342020124, -0.342020124, 3.348487e-08, -0.939692557), easingstyles.Back, easingdirs.Out},
			raw = {CFrame.new(0.659713745, -1.45935869, 0.354370117, 0.99999994, -2.98023224e-08, 3.35276127e-08, 3.53902578e-08, -3.21306288e-08, -0.999999881, -2.98023224e-08, 1, -3.0035153e-08), easingstyles.Back, easingdirs.Out},
			law = {CFrame.new(-0.000568389893, -1.6040411, -2.10723114, -0.0793336332, -0.53615725, 0.840381742, 0.862421989, -0.459712416, -0.211878672, 0.499934286, 0.707954705, 0.498864472), easingstyles.Back, easingdirs.Out},
		}
	},
	reload = {
		[1] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Sine, easingdirs.InOut},
			hw = {CFrame.new(-0.055809021, 0, -0.0665130615, 0.766044319, -0.11161875, 0.633022487, -3.7252903e-08, 0.984807789, 0.17364797, -0.642787755, -0.133022055, 0.754406393), easingstyles.Sine, easingdirs.InOut},
			gw = {CFrame.new(-0.0572328568, -0.980491638, -0.278923035, 0.0310192183, 0.998318493, 0.0487680063, 0.937351048, -0.0121154999, -0.34816578, -0.346991748, 0.0565129519, -0.936161935), easingstyles.Sine, easingdirs.InOut},
			raw = {CFrame.new(1.26604462, -0.913009644, -0.537094116, 0.999999821, -3.57627869e-07, 6.27093755e-08, 4.48221016e-10, -0.173648104, -0.984807611, 3.85997794e-07, 0.984807551, -0.173648149) * CFrame.new(0,0,0.5), easingstyles.Sine, easingdirs.InOut},
			law = {CFrame.new(-1.08869362, -1.33496189, -1.19934082, 0.766044259, 4.22527791e-10, -0.642787695, -0.111618742, 0.98480767, -0.133021995, 0.633022428, 0.17364791, 0.754406333) * CFrame.new(0,0,0.5) * CFrame.new(0,-0.8,0), easingstyles.Sine, easingdirs.InOut},
		},
		[2] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Sine, easingdirs.In},
			hw = {CFrame.new(-0.055809021, 0, -0.0665130615, 0.864329457, -0.11161875, 0.490383387, 0.03015358, 0.984807789, 0.171009868, -0.502021194, -0.133022055, 0.854564071), easingstyles.Sine, easingdirs.In},
			gw = {CFrame.new(-0.0572328568, -0.980491638, -0.278923035, 0.0310192183, 0.998318493, 0.0487680063, 0.937351048, -0.0121154999, -0.34816578, -0.346991748, 0.0565129519, -0.936161935), easingstyles.Sine, easingdirs.In},
			raw = {CFrame.new(1.11267471, -0.963647842, -0.780944824, 0.96286577, 0.230811596, -0.140053496, -0.10095071, -0.173324212, -0.979677141, -0.250395477, 0.957436204, -0.143587425) * CFrame.new(0.2,0,0) * CFrame.new(0,0,0.5) * CFrame.Angles(0,-0.05,0), easingstyles.Sine, easingdirs.In},
			law = {CFrame.new(-0.289166451, -0.800122261, -1.59056854, 0.533511698, -0.820919991, -0.203605846, -0.0797704309, 0.190816656, -0.978378952, 0.842022419, 0.53821826, 0.0363177806) * CFrame.new(0,0,0.5) * CFrame.new(0,0,0), easingstyles.Sine, easingdirs.In},
		},
		[3] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Sine, easingdirs.Out},
			hw = {CFrame.new(-0.055809021, 0, -0.0665130615, 0.936352491, -0.11161875, 0.332844049, 0.0593910292, 0.984807789, 0.163175717, -0.34600088, -0.133022055, 0.928756297), easingstyles.Sine, easingdirs.Out},
			gw = {CFrame.new(-0.0572328568, -0.980491638, -0.278923035, 0.0310192183, 0.998318493, 0.0487680063, 0.937351048, -0.0121154999, -0.34816578, -0.346991748, 0.0565129519, -0.936161935), easingstyles.Sine, easingdirs.Out},
			raw = {CFrame.new(0.951341629, -1.00614738, -0.96661377, 0.887119889, 0.393562078, -0.241094485, -0.185951054, -0.173324212, -0.967150807, -0.422421396, 0.902810454, -0.0805761442) * CFrame.new(0.3,0,0) * CFrame.new(0,0,0.5) * CFrame.Angles(0,-0.1,0), easingstyles.Sine, easingdirs.Out},
			law = {CFrame.new(-0.798740387, -0.729963303, -1.94239807, 0.788041711, -0.601489127, -0.131151706, -0.0967602059, 0.0893746093, -0.991286814, 0.60796994, 0.793865442, 0.0122306943) * CFrame.new(0,0,0.5) * CFrame.new(0.5,0,-0.4), easingstyles.Sine, easingdirs.Out},
		},
		[4] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Sine, easingdirs.In},
			hw = {CFrame.new(-0.055809021, 0, -0.0665130615, 0.936352491, -0.11161875, 0.332844049, 0.0593910292, 0.984807789, 0.163175717, -0.34600088, -0.133022055, 0.928756297), easingstyles.Sine, easingdirs.In},
			gw = {CFrame.new(-0.0572328568, -0.980491638, -0.278923035, 0.0310192183, 0.998318493, 0.0487680063, 0.937351048, -0.0121154999, -0.34816578, -0.346991748, 0.0565129519, -0.936161935), easingstyles.Sine, easingdirs.In},
			raw = {CFrame.new(0.951341629, -1.00614738, -0.96661377, 0.887119889, 0.393562078, -0.241094485, -0.185951054, -0.173324212, -0.967150807, -0.422421396, 0.902810454, -0.0805761442) * CFrame.Angles(0,-0.45,0) * CFrame.new(0,0,0.5) * CFrame.Angles(0,-0.15,0), easingstyles.Sine, easingdirs.In},
			law = {CFrame.new(-0.733897209, -0.698638916, -1.94715118, 0.733374, -0.676505506, -0.0670995787, -0.0810378194, 0.0110032074, -0.996650279, 0.67497766, 0.736355007, -0.0467530787) * CFrame.new(0,0,0.5) * CFrame.Angles(0.15,0,0) * CFrame.new(-0.1,0,0), easingstyles.Sine, easingdirs.In},
		},
		[5] = {
			--mw = {CFrame.new(-0.2264328, 0.0250015259, -0.604776859, 0.98480773, 0, 0.173648193, 0, 1, 0, -0.173648193, 0, 0.98480773), easingstyles.Sine, easingdirs.In},
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Sine, easingdirs.Out},
			hw = {CFrame.new(-0.055809021, 0, -0.0665130615, 0.936352491, -0.11161875, 0.332844049, 0.0593910292, 0.984807789, 0.163175717, -0.34600088, -0.133022055, 0.928756297), easingstyles.Sine, easingdirs.Out},
			gw = {CFrame.new(-0.0572328568, -0.980491638, -0.278923035, 0.0310192183, 0.998318493, 0.0487680063, 0.937351048, -0.0121154999, -0.34816578, -0.346991748, 0.0565129519, -0.936161935), easingstyles.Sine, easingdirs.Out},
			raw = {CFrame.new(0.956790924, -0.985137939, -0.964424133, 0.887119889, 0.382671088, -0.258031964, -0.185951054, -0.215345785, -0.95867002, -0.422421396, 0.898436666, -0.119879492) * CFrame.Angles(0,-0.55,0) * CFrame.new(0,0,0.4) * CFrame.Angles(0,-0.1,0), easingstyles.Sine, easingdirs.Out},
			law = {CFrame.new(-0.702912331, -0.529985428, -1.91860962, 0.691018224, -0.696123064, -0.194694132, -0.3362284, -0.0711144507, -0.939091682, 0.639877796, 0.714391232, -0.28319779) * CFrame.new(0,0,0.5) * CFrame.new(0.1,0,0), easingstyles.Sine, easingdirs.Out},
		}
	},
	aim = {
		[1] = {
			bw = {CFrame.new(-0.299999237, 0.104995728, 0.0449981689, 1, 3.33557523e-06, 2.00149793e-06, -3.33557591e-06, 1, 3.57635798e-07, -2.0014968e-06, -3.57642477e-07, 1), easingstyles.Back, easingdirs.Out},
			hw = {CFrame.new(0, 0, 0, 0.642787635, 0, 0.766044438, 0, 1, 0, -0.766044438, 0, 0.642787635), easingstyles.Sine, easingdirs.Out},
			gw = {CFrame.new(-0.209030151, -1.02510452, -0.225169182, 9.54675698e-08, 0.99999994, 8.86497986e-10, 0.939692557, -1.49011612e-07, -0.342020124, -0.342020124, 3.348487e-08, -0.939692557), easingstyles.Sine, easingdirs.Out},
			raw = {CFrame.new(0.659713745, -1.45935869, 0.354370117, 0.99999994, -2.98023224e-08, 3.35276127e-08, 3.53902578e-08, -3.21306288e-08, -0.999999881, -2.98023224e-08, 1, -3.0035153e-08), easingstyles.Sine, easingdirs.Out},
			law = {CFrame.new(-0.000568389893, -1.6040411, -2.10723114, -0.0793336332, -0.53615725, 0.840381742, 0.862421989, -0.459712416, -0.211878672, 0.499934286, 0.707954705, 0.498864472), easingstyles.Sine, easingdirs.Out},
		}
	},
	--individual poses
	reloadmag = {
		[1] = {
			mag = {CFrame.new(0.383216858, 0.00605773926, -0.895876884, 0.982579589, -0.0196594987, -0.184799746, 0.0194191728, 0.999806643, -0.00311047747, 0.184825167, -0.000532366452, 0.982771337), easingstyles.Sine, easingdirs.In}
		},
		[2] = {
			mag = {CFrame.new(-0.341659546, -0.00597381592, -0.82459569, 0.943051159, -0.0805884004, 0.32273832, 0.108094886, 0.99179846, -0.0682025552, -0.314594954, 0.0992048606, 0.944027781) * CFrame.new(-0.2,0.1,0), easingstyles.Sine, easingdirs.Out}
		},
		[3] = {
			mag = {CFrame.new(-0.343078613, 0.033826828, -0.555139065, 0.931312561, -0.056615673, 0.359807789, 0.0651112646, 0.997804642, -0.0115158707, -0.358372539, 0.0341522247, 0.932950974) * CFrame.Angles(0,0.3,0) * CFrame.new(-0.3,0.2,0), easingstyles.Sine, easingdirs.In}
		},
		[4] = {
			mag = {CFrame.new(-0.226425171, 0.0250015259, -0.604773998, 0.984800279, 1.56462193e-06, 0.173645124, 1.68196857e-06, 0.999979436, -5.66244125e-07, -0.173649177, -8.04662704e-07, 0.984803438), easingstyles.Sine, easingdirs.Out}
		}
	}
}

function clonemag(parent, name)
	local clonedmag = magcmodel:Clone()
	local clonedmagpart = clonedmag:WaitForChild("magpart")
	clonedmag.Name = name
	clonedmag.Parent = parent
	return clonedmag, clonedmagpart
end

function tween(speed, easingstyle, easingdirection, loopcount, reverseafterfinish, delaytime, WHAT, goal)
	local info = TweenInfo.new(speed, easingstyle, easingdirection, loopcount, reverseafterfinish, delaytime)
	local goals = goal
	local anim = tweenservice:Create(WHAT, info, goals)
	anim:Play()
end

function linearlerp(a,b,t)
	return a+(b-a)*t
end

function clientdropshell()
	local shell = Instance.new("SpawnLocation", gunmodel) --spawnlocation because its one of the only baseparts that dont go under tusks basepart limit
	shell.Enabled = false
	shell.Name = "shell;"
	shell.Shape = "Cylinder"
	shell.Size = Vector3.new(0.25,0.1,0.1)
	shell.BrickColor = BrickColor.new("New Yeller")
	shell.Material = "Glass"
	shell.Anchored = true
	shell.CanCollide = false
	shell.CFrame = boltcweld.Part1.CFrame * CFrame.new(0.1,0,0)
	shell:BreakJoints()
	local shellfunc
	local shelltimepassed = 0
	local playedshells = false
	local currentshelly = math.random(1,10)/5
	local currentshellx = math.random(8,15)
	local ejectlookv = boltcweld.Part1.CFrame.upVector
	local ejectrightv = boltcweld.Part1.CFrame.rightVector
	shellfunc = runservice.Stepped:Connect(function(_, delta)
		shelltimepassed = shelltimepassed + delta
		shell.CFrame = CFrame.new(shell.Position, shell.Position+ejectlookv) 
			* CFrame.new(0,currentshelly*delta,-currentshellx*delta)
		shell.CFrame = CFrame.new(shell.Position, shell.Position+ejectrightv) 
			* CFrame.Angles(0,math.pi/2,0)
		currentshelly = currentshelly - delta*shellfallspeed
		if shelltimepassed > shellflytime then
			shell:Destroy()
			shellfunc:Disconnect()
		end
	end)
end

function pemit(part, color, minsize, maxsize, minlift, maxlift, speed, direction, lifetime)
	pcall(function() --tusk has a particle emitter limit thats why im pcalling
		local em = Instance.new("ParticleEmitter", part)
		em.Color = ColorSequence.new(color)
		em.Texture = "rbxassetid://375847957"
		em.Name = "gemit"
		em.Drag = 10
		em.EmissionDirection = direction
		em.Speed = NumberRange.new(speed)
		em.Rate = 500
		em.Lifetime = NumberRange.new(minlift,maxlift)
		em.SpreadAngle = Vector2.new(-20,20)
		em.Transparency = NumberSequence.new(0.75, 1)
		em.Size = NumberSequence.new(minsize, maxsize)
		task.spawn(function()
			task.wait(lifetime)
			em.Enabled = false
			debris:AddItem(em, 0.5)
		end)
	end)
end

function muzzleflash(size, transparency)
	local e = Instance.new("SpawnLocation", gunmodel) --spawnlocation because its one of the only baseparts that dont go under tusks basepart limit
	e.Enabled = false
	Instance.new("SpecialMesh", e).MeshType = Enum.MeshType.Sphere
	local lig = Instance.new("PointLight", e)
	lig.Brightness = 1-transparency
	e.Size = size
	e.Transparency = transparency
	e.CanCollide = false
	e.Anchored = true
	e.Material = Enum.Material.Neon
	e.CFrame = gunclufa.CFrame * CFrame.new((-size.x/2)-0.3,0,0)
	pemit(gunclufa, Color3.fromRGB(255,255,255), 0.15, 0.35, 0.1, 0.2, 10, "Left", 0.1)
	debris:AddItem(e, 0.025)
end

function cpose(posname, posnumb, speed, backupt)
	if equiptick == backupt then
		if currentlyfps then
			if posname == "shoot" and posnumb == 1 then
				clientdropshell()
				muzzleflash(Vector3.new(2,0.6,0.6), math.random(1,15)/10)
				if adsing then
					offset = offset * CFrame.new(0,0,0.05) * CFrame.Angles(0,0,0.015)
				else
					offset = offset * CFrame.new(0,0,0.1) * CFrame.Angles(0,0,0.03)
				end
			elseif posname == "equip" and posnumb == 2 then
				recoiltick = tick()
				recoilup(0, -0.35, 1, 0.3, recoiltick)
				if bchambered.Value > 0 then
					clientdropshell()
				end
			elseif posname == "reload" then
				if posnumb == 1 then
					recoilup(-0.7, 0.3, -1, 0.4, recoiltick)
				end
			end
		end
		tween(speed, poses[posname][posnumb].raw[2], poses[posname][posnumb].raw[3], 0, false, 0, rarmcweld, {C0 = poses[posname][posnumb].raw[1]})
		tween(speed, poses[posname][posnumb].law[2], poses[posname][posnumb].law[3], 0, false, 0, larmcweld, {C0 = poses[posname][posnumb].law[1]})
		tween(speed, poses[posname][posnumb].gw[2], poses[posname][posnumb].gw[3], 0, false, 0, guncweld, {C0 = poses[posname][posnumb].gw[1]})
		tween(speed, poses[posname][posnumb].bw[2], poses[posname][posnumb].bw[3], 0, false, 0, boltcweld, {C0 = poses[posname][posnumb].bw[1]})
	end
end

function ciposeconvert(posname, posnumb, posdir, speed, backupt)
	if equiptick == backupt then
		if posname == "reloadmag" then
			if posnumb == 1 then
				reloadmagcmodel, reloadmagcpart = clonemag(guncmodel, "mag")
				reloadmagcweld = Instance.new("Weld", reloadmagcmodel)
				reloadmagcweld.Name = "handmagweld"
				reloadmagcweld.Part0 = maincpart
				reloadmagcweld.Part1 = reloadmagcpart
				reloadmagcweld.C0 = CFrame.new(0.771263123, -2.07442856, -2.45114708, 0.108410954, 0.822345078, -0.558561325, -0.0455624163, 0.565389991, 0.823553741, 0.993062019, -0.0638353601, 0.0987635553)
				if not currentlyfps then
					modeltransparency(reloadmagcmodel, 1)
				end	
			elseif posnumb == 3 then
				local flingmagm, flingmagp = clonemag(guncmodel, "throw")
				local magv = Instance.new("BodyVelocity", flingmagp)
				magv.MaxForce = Vector3.new(1/0,1/0,1/0)
				magv.Velocity = (mainpart.CFrame.lookVector*-math.random(5,10)) + (mainpart.CFrame.rightVector*-math.random(10,20)) + (mainpart.CFrame.upVector*-math.random(10,20))
				local magav = Instance.new("BodyAngularVelocity", flingmagp)
				magav.MaxTorque = Vector3.new(1/0,1/0,1/0)
				magav.AngularVelocity = hrp.CFrame.rightVector*math.random(15,20)
				debris:AddItem(magv, 0.1)
				debris:AddItem(flingmagp, 0.5)
				if not currentlyfps then
					modeltransparency(flingmagm, 1)
				end
				modeltransparency(magcmodel, 1)
			elseif posnumb == 4 then
				task.spawn(function()
					task.wait(0.2)
					reloadmagcmodel:Destroy()
					if currentlyfps then
						modeltransparency(magcmodel, 0)
					end
				end)
			end
		end
		tween(speed, poses[posname][posnumb][posdir][2], poses[posname][posnumb][posdir][3], 0, false, 0, reloadmagcweld, {C0 = poses[posname][posnumb][posdir][1]})
	end
end

function movec(cf)
	cam.CFrame = cam.CFrame * cf
end

function recoilup(xm, ym, zm, t, tic)
	local firsttick = tick()
	task.spawn(function()
		while runservice.RenderStepped:wait() and tick() < firsttick + t and recoiltick == tic do
			movec(recoilcf:Inverse())
			recoilcf = recoilcf * CFrame.Angles(
				(xm*delta*(recmult/recdampmult))*((t+firsttick)-tick()), --x
				(ym*delta*(recmult/recdampmult))*((t+firsttick)-tick()), --y
				(zm*delta*(recmult/recdampmult))*((t+firsttick)-tick())  --z
			)
			movec(recoilcf)
		end
	end)
end

remote.OnClientEvent:Connect(function(WHAT, param, param2, param3, param4)
	if state ~= "unequipped" then
		if WHAT == "recoil" then
			recoiltick = tick()
			recoilup(recxamount, (math.random(-10,10)/10)*recyamount, (math.random(-10,10)/10)*reczamount, rectime, recoiltick)
		elseif WHAT == "fromserverpose" then
			cpose(param, param2, param3, equiptick)
		elseif WHAT == "fromserverindividualpose" then
			ciposeconvert(param, param2, param3, param4, equiptick)
		end
	end
end)

function ads(enable)
	if enable and not adsing and hrp.Velocity.Magnitude < 17 and (head.CFrame.p - cam.CFrame.p).Magnitude < 1.7 then
		adsing = true
		recmult = recmult/2
		remote:FireServer("5", true)
	elseif not enable and adsing then
		adsing = false
		recmult = recmult*2
		remote:FireServer("5", false)
	end
end

function makefpsviewmodel()
	viewmodel = Instance.new("Model", cam)
	viewmodel.Name = "gunviewmodel"
	Instance.new("Humanoid", viewmodel)
	local mainpart = Instance.new("Part", viewmodel)
	mainpart.Anchored = true
	mainpart.CanCollide = false
	mainpart.Transparency = 1
	mainpart.Size = Vector3.new()
	--
	local rarm = Instance.new("Part", viewmodel)
	rarm.Size = Vector3.new(0.7,2,0.7)
	rarm.Color = character["Right Arm"].Color
	rarm.CanCollide = false
	rarm.Name = "Right Arm"
	local larm = Instance.new("Part", viewmodel)
	larm.Size = Vector3.new(0.7,2,0.7)
	larm.Color = character["Left Arm"].Color
	larm.CanCollide = false
	larm.Name = "Left Arm"
	local gunclone = gunmodel:Clone()
	local gunchandle = gunclone:WaitForChild("Handle")
	local guncmainpart = gunclone:WaitForChild("mainpart")
	gunclufa = gunclone:WaitForChild("lufa")
	maincpart = guncmainpart
	guncmodel = gunclone
	boltcweld = guncmainpart:WaitForChild("boltweld")
	magcmodel = gunclone:WaitForChild("mag")
	gunclone.Parent = viewmodel
	for i,v in pairs(gunclone:GetDescendants()) do
		if v:IsA("BasePart") then
			v.CanCollide = false
			v.Anchored = false
		end
	end
	--
	larmcweld = Instance.new("Weld", mainpart)
	larmcweld.Part0 = mainpart
	larmcweld.Part1 = larm
	larmcweld.C0 = CFrame.new(1,-2.5,0)
	rarmcweld = Instance.new("Weld", mainpart)
	rarmcweld.Part0 = mainpart
	rarmcweld.Part1 = rarm
	rarmcweld.C0 = CFrame.new(1,-2.5,0)
	guncweld = Instance.new("Weld", mainpart)
	guncweld.Part0 = rarm
	guncweld.Part1 = gunchandle
	guncweld.C0 = CFrame.new(1,-2.5,0)
	pcall(function()
		character["Shirt"]:Clone().Parent = viewmodel
	end)
	gunmodel.DescendantAdded:Connect(function(WHAT)
		if (cam.CFrame.p - head.Position).magnitude < 1.3 then
			if WHAT.Name == "throwserver" or WHAT.Name == "reloadserver" then
				WHAT:WaitForChild("Part")
				modeltransparency(WHAT, 1)
			elseif WHAT:IsA("ParticleEmitter") and WHAT.Name == "gemit" then
				WHAT.Transparency = NumberSequence.new(1)
			elseif WHAT:IsA("BasePart") and WHAT.Name == "muzzleflash" or WHAT.Name == "shell;" then
				WHAT.Transparency = 1
			elseif WHAT:IsA("PointLight") and WHAT.Name == "mflash" then
				WHAT.Brightness = 0
			end
		end
	end)
	modeltransparency(viewmodel, 1)
	return mainpart
end

tool.Equipped:Connect(function()
	state = "equipped"
	equiptick = tick()
	local backuptick = equiptick
	local ticktofireserver = 0
	local lastcameracf = cam.CFrame
	savedfov = cam.FieldOfView
	offset = CFrame.new()
	character = owner.Character
	gui.Parent = ownergui
	local mpart = makefpsviewmodel()
	mouse.TargetFilter = mpart.Parent
	chamberedgui.Text = tostring(bchambered.Value)
	ammogui.Text = tostring(binmag.Value)
	maggui.Text = tostring(magleft.Value)
	humanoid = character:FindFirstChildOfClass("Humanoid")
	head = character.Head
	hrp = character.HumanoidRootPart
	humanoid.AutoRotate = false
	rstepgun = runservice.RenderStepped:Connect(function()
		if state ~= "unequipped" and humanoid.Health > 0 and equiptick == backuptick then
			delta = tick() - frametick
			movec(recoilcf:Inverse())
			hrp.CFrame = hrp.CFrame:lerp(CFrame.new(hrp.Position, Vector3.new(mouse.Hit.p.x,hrp.Position.y,mouse.Hit.p.z)),delta*15)
			recoilcf = recoilcf:lerp(CFrame.new(),delta*currentcspeed)
			movec(recoilcf)
			humanoid.CameraOffset = Vector3.new()
			if (cam.CFrame.p - head.Position).magnitude < 1.3 and not currentlyfps then
				humanoid.CameraOffset = Vector3.new(0,0.4,0)
				guntransparency(1)
				modeltransparency(viewmodel, 0)
				currentlyfps = true
			elseif (cam.CFrame.p - head.Position).magnitude > 1.3 and currentlyfps then
				guntransparency(0)
				modeltransparency(viewmodel, 1)
				if adsing then
					ads(false)
				end
				currentlyfps = false
			end
			local relative = cam.CFrame:ToObjectSpace(lastcameracf)
			local camx,camy,camz = relative:ToOrientation()
			local relativevel = hrp.CFrame:vectorToObjectSpace(hrp.Velocity)
			local clampvelx, clampvelz, clampvely = math.clamp(relativevel.x, -35, 35), math.clamp(relativevel.z, -35, 35), math.clamp(relativevel.y, -50, 50)
			local crelativevel = Vector3.new(clampvelx, 0, clampvelz)
			if adsing then
				offset = offset:lerp(CFrame.Angles(camx/2, camy/2, -camy/2) * CFrame.new(-0.45,0.4,0.25), delta*5)
				cam.FieldOfView = linearlerp(cam.FieldOfView, 35, delta*4)
			else
				offset = offset:lerp(CFrame.Angles(camx/2, camy/2, -camy/2), delta*10)
				cam.FieldOfView = linearlerp(cam.FieldOfView, 70+(Vector3.new(hrp.Velocity.x,0,hrp.Velocity.z).Magnitude/5), delta*5)
			end
			if crelativevel.Magnitude > 0.1 then
				if crelativevel.Magnitude < 19 or state == "shooting" then
					offset = offset:lerp(CFrame.Angles(
						(camx/2), 
						camy/2-math.cos(tick()*7)*(crelativevel.Magnitude/350), 
						(-camy/2)+math.sin(tick()*7)*(crelativevel.Magnitude/120)-(clampvelx/60)) 
							* CFrame.new(
								math.sin(tick()*7)*(crelativevel.Magnitude/250),
								-math.cos(tick()*14)*(crelativevel.Magnitude/250),
								0), delta*5)
				elseif state ~= "shooting" and humanoid.FloorMaterial ~= Enum.Material.Air then
					if adsing then
						ads(false)
					end
					offset = offset:lerp(CFrame.Angles(
						camx/2, 
						camy/2-math.cos(tick()*10)*(crelativevel.Magnitude/250), 
						(-camy/2)+math.sin(tick()*10)*(crelativevel.Magnitude/70)-(clampvelx/60)) 
							* CFrame.new(
								1+math.sin(tick()*10)*(crelativevel.Magnitude/150),
								-0.4-math.cos(tick()*20)*(crelativevel.Magnitude/150),
								0)
							* CFrame.Angles(
								math.rad(-20),
								(math.pi/2),
								0), delta*10)
				end
			end
			mpart.CFrame = cam.CFrame * offset
			lastcameracf = cam.CFrame
			ticktofireserver = ticktofireserver + delta
			if ticktofireserver > 0.1 then
				remote:FireServer("1", (mouse.Hit.p-head.CFrame.p).unit.y)
				ticktofireserver = 0
			end
		else
			rstepgun:Disconnect()
		end
		frametick = tick()
	end)
end)
mouse.KeyDown:Connect(function(key)
	if state == "equipped" then
		key = key:lower()
		if key == "f" then
			remote:FireServer("3")
		elseif key == "r" then
			remote:FireServer("4")
		elseif key:byte() == 48 then
			remote:FireServer("6", true)
		end
	end
end)
mouse.KeyUp:Connect(function(key)
	if state == "equipped" then
		key = key:lower()
		if key:byte() == 48 then
			remote:FireServer("6", false)
		end
	end
end)
mouse.Button2Down:Connect(function()
	if state ~= "unequipped" then
		ads(true)
	end
end)
mouse.Button2Up:Connect(function()
	if state ~= "unequipped" then
		ads(false)
	end
end)
tool.Activated:Connect(function()
	if state == "equipped" then
		shoottick = tick()
		state = "shooting"
		local btick = shoottick
		while shoottick == btick and state == "shooting" and humanoid.Health > 0 do
			if binmag.Value > 0 or bchambered.Value > 0 then
				remote:FireServer("2", mouse.Hit.p)
				task.wait(gunspeed.Value)
			else break end
		end
		if state == "shooting" then
			state = "equipped"
		end
	end
end)
tool.Deactivated:Connect(function()
	if state == "shooting" then
		state = "equipped"
	end
end)
tool.Unequipped:Connect(function()
	state = "unequipped"
	gui.Parent = tool
	viewmodel:Destroy()
	guntransparency(0)
	if adsing then
		ads(false)
	end
	cam.FieldOfView = savedfov
	currentlyfps = false
	recoilcf = CFrame.new()
	humanoid.AutoRotate = true
end)