How to run characterAdded function when the player joins

Hello developers, I am currently working on a stage system. I have a function which runs everytime a character gets added to workspace, however when the character loads in for the first time it doesn’t work. Here is the script:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer


local leaderstats = Player:WaitForChild("leaderstats")
local Stage = leaderstats:WaitForChild("Stage")
local MaxLevel = Player:WaitForChild("MaxLevel")


local Checkpoints = workspace:WaitForChild("Checkpoints")


Player.CharacterAdded:Connect(function(Character)
	-- Character is not detected the first time player joins the game. 
	Character:WaitForChild("HumanoidRootPart")
	Character:MoveTo(Checkpoints[tostring(MaxLevel.Value)].Position)
end)

Thanks in advance.

3 Likes

Hey im not sure if this works or if this makes any difference, however instead of using a function for characteradded, use:

local Character = Player.Character or Player.CharacterAdded:Wait()
3 Likes

It works, Thanks for the reply.

2 Likes

No problem

Char limit

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.