How can I make this run perfect

So what i’m trying to do is when i select a slot i’m about to play on it only select that slot and not fire the other slots but the slot i chose

game.ReplicatedStorage.MainMenuSlotClick.OnServerEvent:Connect(function(Player, SlotName)
	local PlrGui = Player.PlayerGui
	local Main = PlrGui.MainMenu.Main

	local PurchasedSlots = Profiles[Player].Data.PurchasedSlots
	local PurchasedSlots2 = Player.PurchasedSlots

	if SlotName == "PurchaseSlot" then
		if PurchasedSlots >= 4 then return end
		if PurchasedSlots2.Value >= 4 then Player:Kick("You've been kicked by the anti-cheat (Error 04)") end

		if not Player or not Player:IsDescendantOf(game.Players) then return end

		MPS:PromptProductPurchase(Player, PurchaseSlotProductId)
	else
		local SlotNum = string.sub(SlotName, string.len(SlotName), string.len(SlotName))

		if  Player:FindFirstChild("DataSlot"..SlotNum) then
			game.ServerStorage:WaitForChild('PlayerData'):WaitForChild(Player.Name).Stats.Race.Value = Player:FindFirstChild("DataSlot"..SlotNum).Race.Value	
			print("Race Changed")
			print(Player:FindFirstChild("DataSlot"..SlotNum).Outfit.Value)
			game.ServerStorage:WaitForChild('PlayerData'):WaitForChild(Player.Name).Stats.BattlePower.Value = Player:FindFirstChild("DataSlot"..SlotNum).Level.Value	
		end

		if not Main:FindFirstChild(SlotName) then Player:Kick("You've been kicked by the anti-cheat (Error 01)") end
		if PurchasedSlots < tonumber(SlotNum) then Player:Kick("You've been kicked by the anti-cheat (Error 02)") end
		if PurchasedSlots2.Value < tonumber(SlotNum) then Player:Kick("You've been kicked by the anti-cheat (Error 03)") end
		if Player:FindFirstChild("PlayingSlot") then  end

		if not Player or not Player:IsDescendantOf(game.Players) then return end

		local ChosenSlot = Player.PlayingSlot
		ChosenSlot.Value = SlotNum

		if  game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").PlayingSlot.Value == 1 then
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData1.Value = 1		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData1.Value = 1	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData2.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData2.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData3.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData3.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData4.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData4.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData1.Value = 1
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData1.Value = 1
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData2.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData2.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData3.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData3.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData4.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData4.Value = 0
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills2:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData2
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills3:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData3
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills4:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData4
					print(V.Value)
				end
			end
			DataModule.SaveData(Player)

		end
		if  game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").PlayingSlot.Value == 2 then
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData1.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData1.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData2.Value = 2	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData2.Value = 2	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData3.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData3.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData4.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData4.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData1.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData1.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData2.Value = 2
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData2.Value = 2
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData3.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData3.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData4.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData4.Value = 0	
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData1
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills3:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData3
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills4:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData4
					print(V.Value)
				end
			end
			DataModule.SaveData(Player)
		end
		if  game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").PlayingSlot.Value == 3 then
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData1.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData1.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData2.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData2.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData3.Value = 3		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData3.Value = 3	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData4.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData4.Value = 0	
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData1.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData1.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData2.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData2.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData3.Value = 3
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData3.Value = 3
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData4.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData4.Value = 0
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills2:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData2
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData1
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills4:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData4
					print(V.Value)
				end
			end
			DataModule.SaveData(Player)
		end
		if  game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").PlayingSlot.Value == 4 then
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData1.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData1.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData2.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData2.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData3.Value = 0		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData3.Value = 0	
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").SkillData4.Value = 4		
			game.ServerStorage.PlayerData[Player.Name]:FindFirstChild("Stats").ItemData4.Value = 4	
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData1.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData1.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData2.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData2.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData3.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData3.Value = 0
			game.ServerStorage.PlayerData[Player.Name].Stats.SkillData4.Value = 4
			game.ServerStorage.PlayerData[Player.Name].Stats.ItemData4.Value = 4
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills2:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData2
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills3:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData3
					print(V.Value)
				end
			end
			for _,V in pairs(game.ServerStorage.PlayerData[Player.Name].Skills:GetChildren()) do
				if V:IsA('NumberValue') then
					V.Parent = game.ServerStorage.DataItems.SkillsData1
					print(V.Value)
				end
			end
					DataModule.SaveData(Player)
end
		game.ReplicatedStorage.MainMenuSlotClick:FireClient(Player)

		ProcessAfterCode(Player.Name, tostring(SlotNum)) -- Do whatever you want with this function, this will happen after the Player selects a slot!
	end		
end)