Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 05 Jun 2015 11:34 PM |
| What is an Efficient way to get a LocalPlayer from a regular script? |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2015 11:36 PM |
local plr = game.Players.(YOURNAMEHERE)
Let's see if you fall for it. |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2015 11:36 PM |
There isn't any. Unless u know the player, then there is no point.
However, if you are using FilterEnabled (preferrably, not required), you can use RemoteEvents to send and recieve the player and whatever arguments you want to pass. |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 05 Jun 2015 11:40 PM |
That makes very little sense in the context you provided.
Why do you want to get the LocalPlayer from a server-side script? What makes the LocalPlayer different from any other player? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 05 Jun 2015 11:41 PM |
for i,v in pairs(game.Players:GetChildren()) do print(v.Name) end
Bam. 2ez |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2015 11:42 PM |
@TimeTicks
Oh ho! You got me! *sunglasses* |
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 05 Jun 2015 11:46 PM |
| What I mean is, I need to find the LocalPlayer who touches the brick. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 05 Jun 2015 11:48 PM |
script.Parent.Touched:connect(function(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human then local player = game.Players:GetPlayerFromCharacter(human.Parent) print(player.Name) end end) |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 05 Jun 2015 11:49 PM |
HAAAAAAAAAAAAAAFJSDIFRNGERG
-- local players = game:GetService("Players") local part = script.Parent
part.Touched:connect(function(hit) local character = hit.Parent local player = players:GetPlayerFromCharacter(hit.Parent) if player then --code end end) |
|
|
| Report Abuse |
|
|
Tokimonu
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 643 |
|
|
| 05 Jun 2015 11:49 PM |
i would do it like
game.Players.PlayerAdded:connect(function(plr) print(plr.Name) end)
then if you know how to script you could go on from there |
|
|
| Report Abuse |
|
|
|
| 05 Jun 2015 11:52 PM |
| The localplayer of a localscript is the player whos client the localscript is ran on. Since server-scripts run on the server and not any particular client, there is no localplayer. |
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 05 Jun 2015 11:53 PM |
Ok let me re-phrase what I said...sorry :(
I just need to figure out how to get the 'LocalPlayer' from when a player hits the textbutton. I can script it from there. (think of an if statement) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 05 Jun 2015 11:55 PM |
gui.MouseButton1Click:connect(function(player) print(player.Name) end) |
|
|
| Report Abuse |
|
|
Tokimonu
|
  |
| Joined: 18 Sep 2009 |
| Total Posts: 643 |
|
|
| 05 Jun 2015 11:56 PM |
if it's a gui why not just use localscripts? they're pretty |
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 06 Jun 2015 12:01 AM |
| because the script has to be inside the button |
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 06 Jun 2015 12:02 AM |
@timeticks
error:
attempt to index local 'player' |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 06 Jun 2015 12:03 AM |
| oh i forgot mousebutton1click is stupid and doesnt allow that |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2015 12:05 AM |
>>I just need to figure out how to get the 'LocalPlayer' from when a player hits the textbutton.
I already explained to you, there isn't one in a normal script. You can, however, move up parent by parent to the player. Example:
Hierarchy: Player PlayerGui ScreenGui TextButton Script
So you would do this to get the player: local player = script.Parent.Parent.Parent.Parent
Although it is recommend you always use localscripts to handle guis and then if the server needs to handle some part of the gui, use a remoteevent or remotefunction to contact it. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 06 Jun 2015 12:08 AM |
| TextButton? So it's a gui object.. Gui objects should be in PlayerGui anyways. So just use a localscript? |
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 06 Jun 2015 12:11 AM |
| It's a surfacegui on a brick. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 06 Jun 2015 12:11 AM |
local player = game.Players.LocalPlayer
|
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
| |
|
|
| 06 Jun 2015 12:14 AM |
| You have to put the SurfaceGui in the Player's PlayerGui, then set the SurfaceGuis Adornee to the brick you would like it to display on. It is also advisable that you use a LocalScript rather than a server-script to reduce latency and unnecessary load on the server. |
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 06 Jun 2015 12:25 AM |
| How can I set it "Adornee" to a block? |
|
|
| Report Abuse |
|
|
Vritix
|
  |
| Joined: 01 Jan 2011 |
| Total Posts: 2790 |
|
|
| 06 Jun 2015 12:31 AM |
| Let me re-phrase that... the 'Adornee' option is locked, how can I unlock it? |
|
|
| Report Abuse |
|
|