PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

ClickDetector Example

ClickDetector Example

Oct 01 2018, 1:40 AM PST

Place this code inside a Script inside a ClickDetector. The code sample first creates a reference to the ClickDetector parent and defines a function to show a message that greets a player. Finally, it connects the ClickDetector/MouseClick|MouseClick event of the ClickDetector to the defined function.

local clickDetector = script.Parent

local function onClicked(player)
	-- Show a message to the player
	local msg = Instance.new("Message")
	msg.Parent = player:FindFirstChild("PlayerGui")
	msg.Text = "Hello, " .. player.Name
	wait(2.5)
	msg:Destroy()
end
-- Connect the function to the MouseClick event
clickDetector.MouseClick:Connect(onClicked)