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: Is there a way to detect which player clicked?

Previous Thread :: Next Thread 
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 09:27 PM
a clickdetector

Report Abuse
janthran is not online. janthran
Joined: 15 May 2009
Total Posts: 17429
22 Dec 2013 09:28 PM
script.Parent.ClickDetector.MouseClick:connect(function(plr) print(plr) end)
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 09:30 PM
local torso = plr.Character.Torso

Would that be correct? or is it already in the chracter
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 09:51 PM

script.Parent.ClickDetector.MouseClick:connect(function(plr)

local torso = plr.Character.Torso
if script.Parent.Parent.Press.pending == true then
torso.CFrame = CFrame.new(60.258, 83.4, -263.102)
end
end)

This isn't outputting anything, or erroring.

I'm assuming I'm indexing wrong--do you have any ideas?
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
22 Dec 2013 09:56 PM
"script.Parent.ClickDetector.MouseClick:connect(function(plr)"

Even though you defined plr, it won't be the player itself. It will be the brick that touched it. So you need something like:

script.Parent.ClickDetector.MouseClick:connect(function(part)
if game.Players:findFirstChild(part.Parent) then
local torso=part.Parent:findFirstChild("Torso")
if script.Parent.Parent.Press.pending == true then
torso.CFrame = CFrame.new(60.258, 83.4, -263.102)
end
end
end)
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 09:59 PM
script.Parent.ClickDetector.MouseClick:connect(function(plr)

local torso = plr.Character.Torso
print(plr)
print(script.Parent.Parent.Press.pending.Value)
if script.Parent.Parent.Press.pending == true then
torso.CFrame = CFrame.new(60.258, 83.4, -263.102)
end
end)

prints the player and the value but doesn't teleport the player--should I not use .cframe for teleporting?
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:04 PM
Wrecker I think you may be onto something

however I got this error using your updated version

20:03:20.272 - Workspace.Boosta.button.Script:5: attempt to index global 'part' (a nil value)


line 5
if game.Players:findFirstChild(part.Parent) then

line 6

local torso=part.Parent:findFirstChild("Torso")
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:07 PM
bump
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
22 Dec 2013 10:08 PM
That's because part is undefined, but will only get defined once something touches the brick.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:10 PM
This is a click detector not a ontouched?
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
22 Dec 2013 10:11 PM
I mean clicked.

This part defines it (once clicked): "script.Parent.ClickDetector.MouseClick:connect(function(part)"
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:14 PM
It prints after it is clicked, so it should work but it doesn't.
Full updated script:


script.Parent.ClickDetector.MouseClick:connect(function(plr)

print(plr)
if game.Players:findFirstChild(part.Parent) then
local torso=part.Parent:findFirstChild("Torso")

if script.Parent.Parent.Press.pending == true then
torso.CFrame = CFrame.new(60.258, 83.4, -263.102)
end end
end)
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:17 PM
buwmp
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
22 Dec 2013 10:17 PM
Nevermind. I checked the wiki, I was wrong. It should be:

script.Parent.ClickDetector.MouseClick:connect(function(player)
player.Character:WaitForChild("Torso") --waits until Torso exists (saftey measure)
if script.Parent.Parent.Press.pending==true then
player.Character.Torso.Position=CFrame.new(60.258, 83.4, -263.102)
end
end)
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
22 Dec 2013 10:19 PM
Your updated script should work too, but change part.Parent into plr for it to work.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:21 PM
Neither of them are working :/
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:30 PM
bump
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
22 Dec 2013 10:30 PM
player.Character.Torso.CFrame=CFrame.new(60.258, 83.4, -263.102)
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:40 PM
that doesn't work either
ill upload my thing as a model

http://www.roblox.com/script-help-item?id=139478541
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
22 Dec 2013 10:44 PM
"if script.Parent.Parent.Press.pending == true then "
Should probably be
"if script.Parent.Parent.Press.pending.Value == true then "
if it's a boolvalue
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
22 Dec 2013 10:46 PM
script.Parent.ClickDetector.MouseClick:connect(function(plr)

print(plr)
if game.Players:findFirstChild(plr) then
local torso=part.Parent:findFirstChild("Torso")

if script.Parent.Parent.Press.pending.Value == true then
player.Character.Torso.CFrame=CFrame.new(60.258, 83.4, -263.102)
end end
end)

when I updated it to that it still fails to work

thank you for catching that though
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
22 Dec 2013 10:47 PM
Stop adding random stuff... People are giving you the script.

script.Parent.ClickDetector.MouseClick:connect(function(plr)
local torso=player.Character.Torso

if script.Parent.Parent.Press.pending.Value == true then
player.Character.Torso.CFrame=CFrame.new(60.258, 83.4, -263.102)
end

end)
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
22 Dec 2013 10:48 PM
print(plr) should be print(plr.Name)

and also


if game.Players:findFirstChild(plr.Name) then


plr is the PlayerObject though... No need to use game.Players:findFirstChild(plr) or anything...
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
22 Dec 2013 10:49 PM
"print(plr) should be print(plr.Name)"
No, not necessarily. Print tostrings() all its arguments
Report Abuse
Wreckerbuster67 is not online. Wreckerbuster67
Joined: 29 Jul 2012
Total Posts: 1144
22 Dec 2013 10:50 PM
This is what I came up with based on your model.

script.Parent.ClickDetector.MouseClick:connect(function(plr)
if plr.Character:findFirstChild("Torso") and script.Parent.Parent:findFirstChild("Press").pending.Value==true then
plr.Character.Torso.Position=CFrame.new(60.258, 83.4, -263.102)
end
end)
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