Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

what is localplayer called on a script ?

if local script can do localplayer , what about the script ,since I heard localplayer doesnt work on a script ?

1 comment

0

you can use :GetPlayerFromCharacter() when you use a touch event or something else

2 answers

LocalPlayer can be accessed through a LocalScript. This is because a LocalScript is intended to be replicated for every player.

The script can access the player model through RemoteEvents, or just searching for them manually.

If this is the answer you looked for, then make this an accepted answer.

If you have any other questions respond.

Any LocalScript, allows you to Automatically Hook-Into that Client (LocalPlayer). Since the LocalScript, is directly replicated on that; specific Client.

Scripts, are a-bit different; and are usually called "ServerScripts". In this case, ServerScripts are only replicated/available on the Server. Meaning, you can't directly access a certain player, without specifying their name, userId, etc.

Examples:

--//LocalScript

local plr = game:GetService("Players").LocalPlayer -- As said, this player is LOCAL to the Script.

print(plr.Name) 

--//ServerScript

repeat wait() until game:IsLoaded() -- Server Loads before Client/Players... Or, Just wait(#)

Players = game:GetService("Players")

local Name = "PlayerName" -- For actual ServerScript, having a Preset Name isn't a good idea. Best to-have Remote Function, call from Client-Server. Parsing Player Name.

local plr = Players[Name]

print(plr.Name) 

Despite all this, I'd highly recommend looking at this:

https://scriptinghelpers.org/guides/server-client-relationship-in-roblox

Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.