I really need help with that as it is required for my script.
Is there a way to use game.Players.Localplayer but in regular scripts?
1 answer
It is a little more complicated to find the local player via global script, although it can still be achieved.
One way that the player can be found would be to do the following:
game.Players.PlayerAdded:connect(function(plr)
-- do stuff
end)
In this case, 'plr' would be that local player.
In addition to finding the player by a PlayerAdded event, it can also be achieved via the Touched event:
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = hit.Parent:GetPlayerFromCharacter()
end
end)
5 comments
Thanks!
Glad it helped! :D
I have one more question, how would I use it in an if statement that does this: ID = 1337 if ID == game.Players.LocalPlayer.UserId then
You're not necessarily getting the LocalPlayer. The LocalPlayer is only accessible in LocalScripts. What you are doing is utilizing an event that provides the player object. So you would need to find some way to get a hold of the player through what ever event you need to use. https://scriptinghelpers.org/blog/common-mistakes#ServerScripts
can it be found in a clicked event
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Regular Scripts live on the server, but there's multiple players playing. Which one is the "local player"?