How Do I Find "player" in a Script not a LocalScript?

How would i find example some like:

local player = what goes here?

Depends.

If the script is in StarterPlayerScripts (runs once per game) you can do

game.Player.PlayerAdded:Connect(function(player) 

end)

If the script is in StarterCharacterScripts (Runs every respawn, script parented under character model) you can do

local character = script.Parent
local player = game.Players:GetPlayerFromCharacter(character)

You can also use remote events:

2 Likes

Thank so much for this information I’m still learning about scripts been using LocalScripts

There are many ways to get the player from a server script, and most of the ways are listed in the thread below.

1 Like

I’m just trying to make a simple UI text to show up on the screen for a few seconds using some similar to:

player.Name…” Owner Joined”

I don’t see why you need the server for this. A LocalScript works just fine:

--LocalScript in StarterPlayerScripts
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	--instead of printing use that in a UI property or something
	print(player.Name.." joined!")
end)
1 Like

Its not really necessary for a script to be linked to a single player, but unless you have it in starterplayer, you cna just uae script.parent. a regular script isnt really the job to handle things just for the llayer like UI and Tweening.

I think that you’re a bit abusing server scripts as others mentioned. But there’s a way - for example, you can place it inside StarterPlayerScripts.

local player = script.Parent.Parent
--script's located in game.Players.A.PlayerScripts
print(player.Name)

or how others mentioned:

I also recommend you use :sparkles: search :sparkles: capabilities before posting.

I believe this worked lol! <3 Anyways, Thanks for the help, I confuse myself w this code having dyslexia isnt ideal LOL.

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