I’m trying to find when a character spawns through CharacterScripts, but so far I’ve had no luck with anything. I’m well aware of being able to get it through GetService:(“Players”), but that does NOT work for what I’m trying to do (making a timer based on how long a player has been alive.)
If you know how to make this version of the script work (or just have some kind of alternative) that would be appreciated.
here’s the script that isn’t working. (no errors, no print.)
I’ve tried using player:Chatted, and that seems to work, so I assume that the CharacterAdded part is where I’ve gone wrong, but I haven’t found any alternatives.
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
player.CharacterAdded:Connect(function()
print("character found")
end)
any solutions or suggestions are greatly appreciated!
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
player.CharacterAdded:Connect(function()
if script.Parent == character then
print("character found")
end)
I’m sorry if it doesn’t work, I started programming with lua only 3 months ago.
Figured it out mere minutes after posting, but here’s the solution for any who want to use this for themselves.
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
if player.CharacterAdded then
print("character found")
end