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

Is there a way to use game.Players.Localplayer but in regular scripts?

Asked by 8 years ago

I really need help with that as it is required for my script.

0
Regular Scripts live on the server, but there's multiple players playing. Which one is the "local player"? BlueTaslem 18071 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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)
0
Thanks! Awsomeman511 30 — 8y
0
Glad it helped! :D Celeritas 10 — 8y
0
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 Awsomeman511 30 — 8y
0
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 M39a9am3R 3210 — 8y
0
can it be found in a clicked event User#25068 0 — 5y
Ad

Answer this question