You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Okay so I am trying to do things with Characters after using LoadCharacter like let’s say printing Character’s name by using a different script
What is the issue? Include screenshots / videos if possible!
Both are server script not client
This is script 1
local function OnReset(player)
player:LoadCharacter()
end
task.wait(5)
OnReset()
-- I know that function will not run with this script I just cut the other parts
-- otherwise it will be too complicated
-- so just think it works and LoadCharacter fires
So it will only print Character.Name when player joins the game not when I call OnReset function
how can I print Character.Name without using Player.PlayerAdded ?
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have read the documantation about the Player and loadCharacter and CharacterAdded.
I suggest using a BindableEvent. Fire it from the script you’re loading the character fom, you can also send through the playerObject as a parameter if you really feel like it, then detect the event being fired from the other script.
-- firing the function
bindableEvent:Fire(...)
-- detecting the function
bindableEvent.Event:Connect(function(...)
end)
If you really feel like it you could make a bindableEvent for each player, then inside the playerAddedfunction when detecting the player respawning do something like:
-- inside the PlayerAdded function:
local bindable = Instance.new("BindableEvent")
bindable.Name = "onCharacterLoaded"
bindable.Parent = player
local function onCharacterAdded(character)
character = character or player.Character
end
if player.Character then onCharacterAdded(player.Character) end
player.CharacterAdded:Connect(onCharacterAdded)
bindable.Event:Connect(onCharacterAdded)
Then when getting the event do:
-- after firing the :LoadCharacter()
local bindable = player:FindFirstChild("onCharacterLoaded")
if bindable then
bindable:Fire(player.Character) -- if you got the character obj as a var already put that in
else
warn(player.Name .. "'s onCharacterLoaded bindable not found!")
end