Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

what is localplayer called on a script ?

Asked by 4 years ago

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

0
you can use :GetPlayerFromCharacter() when you use a touch event or something else Nguyenlegiahung 1091 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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.

Ad
Log in to vote
0
Answered by
Farsalis 369 Moderation Voter
4 years ago
Edited 4 years ago

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!

Answer this question