Character Not teleporting?

game:GetService("Players").PlayerAdded:Connect(function(player)
	addData(player) -- Gives the players Data
	player.CharacterAdded:Connect(function(char)
		repeat wait() until player.Character ~= nil -- Repeats until there is a players Character
		
		print(player.leaderstats.Stage.Value) -- Check to see if this prints
		
		Checkpoint.Check(player, char)	 -- Teleport to current stage // Module
		
		local humanoid -- Empty Variable
		
		repeat
			humanoid = char:FindFirstChild("Humanoid")
			wait()
		until humanoid -- Repeats until there is a humanoid
		
		
		humanoid.Died:Connect(function()
			player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1
			Death.DeathAnimation(player)
		end)

		print(player.leaderstats.Stage.Value) -- Another Check
	end)
end)

So What is meant to happen is When I spawn in My character should go to the current checkpoint which his Stage.value is but Instead doesn’t. This is the module script for the teleport:

Checkpoint.Check = function(player, character)
	local Stage = player:WaitForChild('leaderstats').Stage
	local Checkpoint = game.Workspace:WaitForChild("Checkpoints"):WaitForChild(Stage.Value)
	
	wait(0.1)
	character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(Checkpoint.Position + Vector3.new(0,5,0), Checkpoint.Position)
	character:WaitForChild("HumanoidRootPart").Orientation = Vector3.new(0,0,0)
	
end

For now, I have seemed to fix this issue. I simply made a new script which does handles all the checkpoint, teleport and deaths.

To further explain, since I get that someone with a similar issue may not understand. So I created a module script, however this was a while ago and could have easily been done with a simple function.

-- For the checkpoint
local function Checkpoint(player, Character)
   local Stage = player:WaitForChild("leaderstats").Stage
   local Checkpoint = game.Workspace:WaitForChild("Checkpoints"):FindFirstChild(Stage.Value)
   Character:MoveTo(Checkpoint.Position)
end

What this does is get the current players stage value, and get the checkpoint part which they will be teleported to. In this case I have a folder called checkpoints and it will look for the corresponding stage part and it will then teleport the character to it. This function should be called when CharacterAdded Event is running. This was the fix to the current problem. Hope this helps.

1 Like