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

How would I get the local player from a script, not a local script?

Asked by 6 years ago

I made a script that has a bunch of global's and I want to know if it is possible to get the player from a regular script because, my script works in a regular script only and doesn't in a local but, I am using local player, so Idk where to start.. Any help..?

0
You can't use LocalPlayer in a server script because server scripts can't do anything related to the client. R_alatch 394 — 6y
0
You cannot. How would it know what player you want? hiimgoodpack 2009 — 6y
0
you can use remoteevents or other events to get the player you want Filipalla 504 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

You get the player when you use Events. to get the player from the Touched event, you do:

brick.Touched:Connect(function(limb) -- Touched returns the part that touched "brick"
    local player = game.Players:GetPlayerFromCharacter(limb.Parent)
    if player then
        player.Character:BreakJoints() -- kills character
        player.leaderstats.Points.Value = 1000 -- sets value to 1000 
    end
end)

to get the player from a ClickDetector, do:

ClickDetector.MouseClick:Connect(function(player) -- MouseClick returns the player that clicked
    player.Character:BreakJoints()
    player.leaderstats.Points.Value = 1000
end)

note that the arguments can be named anything

0
I know the touched and click detector stuff... All i needed really was the character stuff greatneil80 2647 — 6y
0
AND THANK YOU FOR ADDING POINTS greatneil80 2647 — 6y
0
Now gotta check if it works in a server greatneil80 2647 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Short answer: nope.

Long answer: Since normal scripts are made to act in the server,there is no way a script can get the local player. Only local scripts can do that because they are made to act in the client.

Answer this question