Character added is not working. I am using a starter character which is just a roblox r15 blocky rig for testing. I don’t know why. No other scripts in game interact with player.
-- services
local Players = game:GetService("Players")
-- variables
local CharacterAlive = true
local Player = Players.LocalPlayer
local Head, Neck
Player.CharacterAdded:Connect(function(character)
Head = character:WaitForChild("Head")
Neck = Head.Neck
end)
print("plyh2")
-- functions
while CharacterAlive do
print("Pluh")
task.wait(0.1)
end
-- events
Player.CharacterAdded:Connect(function()
print("hello")
end)
Player.CharacterAdded:Connect(function()
CharacterAlive = true
end)
Player.CharacterRemoving:Connect(function()
CharacterAlive = false
end)
Perhaps the character added event is being fired before you set the listener for the event. Do a check before setting the listener to see if the character already exists.
No, that’s not what I mean. You have 3 CharacterAdded events connected after one another. just take the code from the last two, and put it into the first one.
You’re right. I found the cause of the problem. Aaand it’s from the our good friend, loops.
The reason nothing prints is because you’re connecting a while wait() do loop before some pretty important events, including the one that prints and the other one that switches alive to true. I would highly recommend putting the loop before any events in the future.
Also, you could put the loop in a task.spawn() function, and that way, you don’t have to move anything.
@BackSpaceCraft is correct though. Its probably better to keep a single listener event. You can delegate other functions to fire from that to keep the code cleaner but multiple listeners is inefficient.