How to do stuff with player's Character after using loadCharacter from another script

You can write your topic however you want, but you need to answer these questions:

  1. 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

  1. 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

This is script 2

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
     print(character.Name)
end)
end)

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 ?

  1. 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.

1 Like

you can use getplayerfromcharacter here is the documentation on it.
Players | Roblox Creator Documentation

1 Like

I am confused about where to put it and how to use it?

1 Like

Whoops sorry about that. i read it wrong this is to do what you are trying to achieve backwards.

2 Likes

What you can do instead

local isrunning = false
local function OnReset(player)
 	isrunning = true
	player:LoadCharacter()
end

task.wait(5)
OnReset()

and then you can do

if isrunning = true then
isrunning = false 
print('the users name here')
1 Like

I do not understand. When using LoadCharacter() it will also write the name

1 Like

scrip 2 can’t know What “isrunning” Equals to if you won’t define it

1 Like

I want to print name from another script

1 Like

Do you want to write the name from the script where LoadCharacter() is executed or what?

1 Like

no, I want to print the name from the other script

1 Like

Can you be more specific? what from what?

1 Like

Bro like what do you mean with more specific? I Want to print Character’s name after LoadCharacter event happened from different script

1 Like

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 playerAdded function 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
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.