That’s strange because i have this function in my game and it adds a hitbox to character.
Alright i have just checked it and it works every time the character is added to the workspace. (not only when he enters the game)
Yeah CharacterAppearanceLoaded will only load once. You’ll want to use CharacterAdded.
Check it again with printing character’s name to be sure.
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(character)
print(plr.Name)
end)
end)
i think he wants just edit some parts of the char only once
try running wait() right after character added event fires
so u could say:
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Wait()
local char = plr.Character
end)
I’m trying to do a custom camera system which imply finding the head. This is the limb that I’m trying to get after the player dies so the script could work properly.
is on the client???
I’m using a local script to modify the camera. So, yes it is on the client.
Oh you should to tell it first.
Then you need local script not server.
Because you can change it’s camera only on a client.
Hm then you can just make a loop with preloadasync for all of the part of your character so.
so if u dont have the local script in the starter character scripts dont use the charcter appearence loaded event
I think you miss understoud, I am using a local script to control the camera.
Try this if you need to load it from client side.
Also you can make same from the server side.
local ContentProvider = game:GetService("ContentProvider")
ContentProvider:PreloadAsync(plr.Character:GetChildren())
print(plr.Name)
ServerSide.
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
coroutine.wrap(function()
local ContentProvider = game:GetService("ContentProvider")
ContentProvider:PreloadAsync(Char:GetChildren())
print(Player.Name.."'s Character loaded")
end)()
end)
end)
I don’t understand how I would go about using this. The function yields until all the given instances are loaded but in my case it is impossible to reference the head until it is loaded. This makes the method useless as the head would not be in the table making the function ignore it.
em you can just create an array and then add there your head
something like this
local array = Char:GetChildren()
table.insert(array,head)
ContentProvider:PreloadAsync(array)
print(Player.Name.."'s Character loaded")
Also wdym by
Do you have a custom head or something?
also i am intrested by this
Can you tell me why do you need to reference the head before it is loaded?
I have two possible solutions. One is to use task.wait() before trying to index the head. task.wait() makes sure a physics step runs before the thread continues. This step is where the limbs are added.
My second solution would to be add a
local head = character:WaitForChild("Head)
and index the head with that variable.
Examples:
Solution 1:
local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function(character)
task.wait()
print(character.Head.Name)
end)
Solution 2:
local player = game.Players.LocalPlayer
player.CharacterAdded:Connect(function(character)
local head = character:WaitForChild("Head")
print(head.Name)
end)
Hope this helps! Let me know if I understood the question wrong or you have any questions.
My problem is that when the event fires, a lot of the times the head is not loaded in the character model making it impossible to reference it as it is not “there” ( loaded ). The reason I said
is because we want to use PreloadAsync() to check when it is loaded but it needs to know what to check which is already what we are trying to solve; we can’t use this as the head don’t “exist” until it is loaded.
task.wait() did not work and as for WaitForChild(), this was my bet but I noticed that it would make a “lag spike” when used. I am not sure if this is due to the function yielding or it working properly but to not waste more time it will use it.
Two things to point out tough, I’m using a mobile device to test; it is a bit laggy and the number of loaded limbs at fire varies each death.
‘CharacterAppearanceLoaded’ will fire each time the player’s avatar’s appearance is loaded, i.e; each time the player’s character is added/spawned.
The following is probably the most favorable way of achieving this, as it is entirely event driven (no polling/yielding).
local Game = game
local Players = Game:GetService("Players")
local function OnPlayerAdded(Player)
local function OnCharacterAdded(Character)
local function OnCharacterChildAdded(Child)
if Child.Name ~= "Head" then return end
print(Child.Name.. " found!")
end
Character.ChildAdded:Connect(OnCharacterChildAdded)
local Head = Character:FindFirstChild("Head")
if Head then OnCharacterChildAdded(Head) end
end
Player.CharacterAdded:Connect(OnCharacterAdded)
end
Players.PlayerAdded:Connect(OnPlayerAdded)