Can i get the character with this script? [SOLVED]

Can i get the character with this script?

--Server Side Script
game.Players.PlayerAdded:Connect(function(Player)
	Character = Player.CharacterAdded:Wait()
end)

to get from everywhere in the script.

It is the actual way or there is any alternative to get it? Like using the remote events.

I dont know why im behaving a problem this. But, everytime i scripting something about character by server script im experiencing this problem.

1 Like

You can get the player when using the Remote Function

1 Like

Can you give example. So i just did it but, i could’nt be sure if it is right.

You can always pass it as a variable

1 Like

It worked as well. But i dont think that was the right way to use remote function.

If I’m understanding correctly, you want to have a separate variable for the character outside the PlayerAdded event??
That’d just make it so each time a player joins their character overrides the value.

1 Like

Yes. I know that is why im asking :grin:.

So you want the overriding or no?

1 Like

No. Im just asking for, if this script is overriding then how would i make an alternative way to it.

Like tell me how you getting character in your server script.

Just do this

game.Players.PlayerAdded:Connect(function(Player) -- Player joined
	Player.CharacterAdded:Connect(function(char) -- Character's player added, includes when the character dies, :LoadCharacter(), and maybe some other stuff idk abt
		-- do stuff here
	end)
end)

alternatively you can put a script inside StarterCharacterScripts and then do

local char = script.Parent

but this ends up creating more scripts than necessary since there’s one script per player. Overall the server is doing the same amount of work though, so idk it’s your call.

1 Like

Oh alright, i understand. So im making OverlapParams. And i need to get character to make it. From the server script. Thats why i want character variable.

I may be misunderstanding, but try this:

--Server Side Script
local PlayersCharactersList = {}
game.Players.PlayerAdded:Connect(function(Player)
	table.insert(PlayersCharactersList,Player.CharacterAdded:Wait())
	--Character = Player.CharacterAdded:Wait()
end)
1 Like

In this

Code
game.Players.PlayerAdded:Connect(function(Player) -- Player joined
	Player.CharacterAdded:Connect(function(char) -- Character's player added, includes when the character dies, :LoadCharacter(), and maybe some other stuff idk abt
		-- do stuff here
	end)
end)

char inside the CharacterAdded event is your character variable, and if you put the code in there you can use it as you were intending for it to be used.

So if you wanted to print a character’s name each time they respawn you’d do

Code
game.Players.PlayerAdded:Connect(function(Player) -- Player joined
	Player.CharacterAdded:Connect(function(char) -- Character's player added, includes when the character dies, :LoadCharacter(), and maybe some other stuff idk abt
		print(char.Name) 
	end)
end)

(wait were you just saying this or were you still asking for something)

1 Like

No. I just wrote that because of maybe you would be get it wrong.

Thanks for everything. I just made it. I dont know who is i gonna check as solution. I will write to title. You both deserving it. Your both script works properly. Thanks

Ohhh I see now ok yeah if you need OverlapParams then go with making a list of the characters like @rfailes said.

Though you’ll need to adjust some things, like adding a CharacterRemoving event to remove values from the list when a character… removes… and stuff like that.

Also mark @rfailes as the solution he gave the list solution.

1 Like

But you deserved too. Thanks but no i wont xd.

Eh up to you and @rfailes then, but it’d be better to give it to someone instead of no one.

Glad I could help though!!

1 Like

Okay then. Thanks for help man.

1 Like