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

Help with ClickDetector?

Asked by 9 years ago

I'm a little rusty on Lua and I forgot how to get the name of the player from a ClickDetector

This is all I got

 function onClicked(click)


    if click.Parent.Name == "Player1" then 

        print("worked")

    else return

    end


end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Any help? Kinda clueless...

1 answer

Log in to vote
0
Answered by 9 years ago

Actually you're not that far off!

Typically I like to call the function right off, so this is what I'll do.

In Click functions, the argument is actually the player itself!

script.Parent.ClickDetector.MouseClick:connect(function(click)-- This is a more efficient way of calling your function!
    if click.Name == "Player1" then -- What you were doing was asking for the game.Players's name!

        print("worked")

    else return

    end
end)

0
Thank you! 1nubcaik 62 — 9y
0
Wouldn't "click" return a nil value on line 2 since you named the player argument "Click" on line 1? M39a9am3R 3210 — 9y
0
@minikitkat @m39 Yup, Error on line 2. Capitalize your letters appropriately please. Validark 1580 — 9y
0
Alright I updated my answer! Thanks for pointing that out! minikitkat 687 — 9y
Ad

Answer this question