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

ClickDetector for one Player only?

Asked by 10 years ago

Anyone know how to make a ClickDetector for one Player only? I can make the rest of the Script, just not the ClickDetector for one person.

1 answer

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

Use a LocalScript with FilteringEnabled (game.Workspace.FilteringEnabled = true) and have the LocalScript add a ClickDetector to a part and connect a clicked event to it.

-- LocalScript
local player = game.Players.LocalPlayer
local playerAllowed = "YourName"

if player.Name ~= playerAllowed then return end

local click = Instance.new("ClickDetector")
local part = game.Workspace:WaitForChild("ClickPart")
click.Parent = part

click.MouseClick:connect(function()
    print("Clicked by", player, ";", script) -- This is debugging so you know it did for sure come from that player.

    -- Your code here
end)
Ad

Answer this question