--this function runs when players join your game

game.Players.PlayerAdded:Connect(function(player)
	DataManger.AddPlayerData(player)
	--this function runs when your player is added to the world, it also runs again when you reset
	player.CharacterAdded:Connect(function(char)
		
		--this is called the player humanoid, it handles a lot of things like animations, jumping, walkspeed
		local humanoid = char:WaitForChild("Humanoid")
		
		
		--this is setting your jump power to 0, too disable player jumping!
		humanoid.JumpPower = 0
		humanoid.JumpHeight = 0
		
		--this is handling for teleporting players to the checkPoints :)
		if player.Data.spawnpoint.Value ~= "" then
			local rootPart = char:WaitForChild("HumanoidRootPart")
			
			local foundCheckpoint = workspace.Interactions.Checkpoints:FindFirstChild(player.Data.spawnpoint.Value)
			
			if foundCheckpoint then
				task.wait(.5)
				
				rootPart.CFrame = (foundCheckpoint.Root.CFrame * CFrame.new(0,3,0))
			else
				warn("NO CHECKPOINT FOUND WITH THE NAME: "..player.Data.spawnpoint.Value.." DID YOU SET UP A CHECKPOINT WITH THAT NAME?")
			end
			
		end
		
	end)
end)

game.Players.PlayerRemoving:Connect(DataManger.RemovePlayerData)
