I am messing around with a character added function, and I cannot seem to get it working.
This is the code, I am just checking for the print to work, and it is on a local script:
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats.Stage.Value
player.CharacterAdded:Connect(function()
print("player added")
end)
It’s in a localscript. If it’s in a localscript playeradded won’t work because the localscript waits for the localplayer to load and then loads so that’s impossible.
You are running the function after the character is already added, try this instead
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local stage = leaderstats.Stage.Value
local function onCharAdded(Char)
print("player added")
end
player.CharacterAdded:Connect(onCharAdded)
if player.Character then onCharAdded(player.Character) end
To make it simple for yourself, you can just do this:
local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:Wait() -- This gets you your character, allowing you to do the stuff down there.
I’ve had this issue before, it wouldn’t allow me to use this on the client so instead, I used my method above ^ Although I just use it to get the character, but my point still stands, which is why I recommend doing