game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
print'test'
end)
end)
Every once and a while this script won’t even run… Why is this?
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
print'test'
end)
end)
Every once and a while this script won’t even run… Why is this?
that doesn’t matter… why would that change anything?
How often does it not print?
Can you get it to stop printing after a certain amount of characters are added?
It’s very rare so it’s hard to test. All I’m doing is pressing play constantly in test mode, sometimes it just doesn’t print at all.
Is it a local script?, Certain it is. If it is change is to a ServerScript
Also its:
print("test")
-- not
print "test"
I got this to work
local Players = game:GetService("Players")
local function onCharacterAdded(character)
print("test")
end
local function onPlayerAdded(player)
print("test1")
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
print'test'
This works completely fine, if you can read what i’m saying is that sometimes it doesn’t print. No, it’s not a LocalScript it’s a ServerScript.
Where did you place this script anyways? By any chance, not in ServerScriptService
?
It’s in serverscriptservice for me, I usually put all my playeradded functions in there.
It should be working, but something else is hindering it. When does it not fire? Does it fire consistently when you reset the character?
Yes, I think the only times when it doesn’t load is whenever I first join.
Sometimes the PlayerAdded event fires before the script connects the signal. That’s why you should loop through existing players as well.
What? I’m confused of what you mean by that. Could you maybe explain what you mean?
It is simply because CharacterAdded
event sometimes doesn’t fire right after PlayerAdded
, which is quite odd in my opinion. Try to look for the player’s character first by Player.Character
, otherwise fall back to Player.CharacterAdded
event.
That’s what I was thinking maybe the character already exists, so I added a print where it checks if Player.Character exists then prints it when the players added to see if it exists + doesn’t fire. I’ll get back to you if it doesn’t print though.
Make sure the player’s character doesn’t already exist:
game.Players.PlayerAdded:Connect(function(Player)
if not Player.Character then Player.CharacterAdded:Wait() end
print("test")
end)
That doesn’t really answer why CharacterAdded doesn’t run occasionally.
Yeah cause its already been answered
game.Players.PlayerAdded:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded
print("Character Exists")
Player.CharacterAdded:Connect(function()
print("Character Spawned")
end)
end)