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

How to define a player in a MouseClick function?

Asked by
Scerzy 85
8 years ago

I know how to do this with Touched scripts, but with a ClickDetector I'm lost. I have this gate and a button, but I only want the button to be activated if the player's name is the same as the Owner.Value within the tycoon. Here's the part I'm having trouble with

script.Parent.ClickDetector.MouseClick:connect(function(clicker)
local player = game.Players:GetPlayerFromCharacter(clicker.Parent)
    if open == false and moving == false and script.Parent.Parent.Parent.Parent.Owner.Value==player then

--gate script stuff

the script is within the button and the open and moving part can be ignored. The script works but when I try and make it run only when the players name matches with the owner value it stops working. Thanks for the help.

1 answer

Log in to vote
0
Answered by
P100D 590 Moderation Voter
8 years ago

I see you've based your script of a part.Touched event, which returns a part. A ClickDetector.MouseClick events always returns a player, never a part (Why would it? There is no part). I would modify your code to look like this:

script.Parent.ClickDetector.MouseClick:connect(function(player)
--Function goes here
end)
Ad

Answer this question