I've looked up all over the web trying to figure out how to do this. I'm either doing everything wrong (me irl haha). back to the point. I can't seem to be able to find the alternative way to call local players in a server script. Ex. Local Script game.Players.LocalPlayer What would i do for a server side script?
LocalPlayer
, as it is not a function. It is a property. You can index it though.DataModel
and the Players
service) of a LocalScript
is, well, the LocalPlayer
. And LocalScript
s run on behalf of the client. Script
s run on behalf of the server.LocalScript
is your LocalScript
, it works for you. But your classroom is your classroom, and in it are your classmates as well as your teacher. Think of the classroom as the server. It has everyone in it, and cannot keep track of who in the heck LocalPlayer
is! For this reason, LocalPlayer
is nil on the server. The server isn't meant to do work for one specific player, but for all. Your game could have multiple players in it, and when you try accessing LocalPlayer
, it can't just randomly pick a player. Code cannot read your mind. This is why it must be all typed out. So instead of doing this:make a part inside of the workspace with color red
local part = Instance.new("Part") part.BrickColor = BrickColor.new("Really red") part.Parent = workspace
ClickDetector.MouseClick
RemoteEvent.OnServerEvent
BasePart.Touched
, getting the player by calling GetPlayerFromCharacter
from Players
RemoteFunction.OnServerInvoke
(callback) Hi there! Here may be the solution you're looking for?
game.Players.PlayerAdded:Connect(function(player) --do stuff here, the argument 'player' serves as a local player end)
This should be as effective as local player... Let me know if you have any more questions! :D