generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How can I get the player of who pressed a gui?

Previous Thread :: Next Thread 
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
21 May 2014 04:24 PM
If the script isn't in the startergui?
Trying to get all my scripts to work in ServerScriptService.
Report Abuse
youssef04 is not online. youssef04
Joined: 22 Jan 2011
Total Posts: 1745
21 May 2014 04:27 PM
function click(p)
--stuff with p, for example: p:Kick()
PATH_TO_GUI.MouseButton1Down:connect(click)
Report Abuse
TehIcyStar is not online. TehIcyStar
Joined: 07 Mar 2010
Total Posts: 1649
21 May 2014 04:29 PM
@youssef lol no. that doesn't work.
Report Abuse
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
21 May 2014 04:30 PM
@Teh, can you tell me how?
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
21 May 2014 04:30 PM
If it's a surface gui, you have to put the gui inside StarterGui and set it's Adornee to the part, if it's a regular gui, you can just use a variable with enough parents to get to player, or this.

script.Parent.Button1Down:connect(function() --I think its MouseButton1Down
local player = script.Parent
repeat wait() player = player.Parent until player:FindFirstChild("PlayerGui")

--things
--player is the player now

end)
Report Abuse
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
21 May 2014 04:33 PM
@Sens

I asked how to do it without the script being in the startergui itself...
Report Abuse
NeonKitty is not online. NeonKitty
Joined: 19 Aug 2010
Total Posts: 87
21 May 2014 04:33 PM
just do

player = script.Parent.Parent.Parent ... (however many parents until you get to the player)

this works because the gui will be located in PlayerGui.
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
21 May 2014 04:34 PM
Well if you use PlayerAdded event, then it's easy!

game.Players.PlayerAdded:connect(function(plr)
plr:WaitForChild("PlayerGui")
plr.PlayerGui.ScreenGui.Frame.TextButton.Button1Down:connect(function()

--stuff

end)
end)
Report Abuse
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
21 May 2014 04:36 PM
NO.

THE SCRIPT THAT WORKS THE GUI IS IN ServerScriptService.
HOW DO I DETECT THE PLAYER THAT CLICKED THE GUI IF I CAN'T DO SCRIPT.PARENT.PARENT.PARENT (etc.)
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
21 May 2014 04:37 PM
Well I just answered it, PlayerAdded is the main way, other than that, it would require other ways which would be more complicated.
Report Abuse
DarkheartSkillz is not online. DarkheartSkillz
Joined: 30 Sep 2011
Total Posts: 5125
21 May 2014 04:38 PM
Wouldn't PlayerAdded stop working if you died?
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
21 May 2014 04:39 PM
Nope! It stops working when you leave.
Report Abuse
TehIcyStar is not online. TehIcyStar
Joined: 07 Mar 2010
Total Posts: 1649
21 May 2014 05:00 PM
Sorry for the late response.

gui buttons' event, MouseButton1Down, doesn't return the player, the only way to do it is, in a local script, have a function that fires the player's name to the remote event, and let a server script pick it up and use that name.

This is how it's done:

http://www.roblox.com/Developer-Product-Sample-place?id=147965737
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image