First, check if the player’s character already exists. You can handle it immediately without relying on the event.
if Player.Character then
-- Handle the existing character here
end
Instead of using a repeat
loop with wait()
, you can use a while
loop and yield the thread with wait()
inside it.
while not (Character:FindFirstChild("Humanoid") and Character:FindFirstChild("LeftUpperArm")) do
wait()
end
It’s possible that the CharacterAdded
event is firing after the player has left the game. You can check if the player is still in the game by using the Parent
property of the player’s character.
Player.CharacterAdded:Connect(function(Character)
-- Check if the player is still in the game
if Player.Character.Parent ~= workspace then
return
end
-- Rest of your code
end)
Hope this helps.