Here is the script:
local re = game.ReplicatedStorage.ClickedButton
function onClick()
re:FireServer()
end
script.Parent.MouseButton1Down:Connect(onClick)
Here is the script:
local re = game.ReplicatedStorage.ClickedButton
function onClick()
re:FireServer()
end
script.Parent.MouseButton1Down:Connect(onClick)
A ClickDetector uses the MouseClick not MouseButton1Down.
You can also use the event in a server Script inside of a part. You will then need to define your ClickDetector in some variable to listen for the mouse click.
Since this is running on the server you don't need to use a remote event at all.
(Server) Script:
local part = script.Parent --The parent of this script
local cd = part.ClickDetector --The detector inside of the part
cd.MouseClick:Connect(function(player)
--run your code in here
--This is running on the server side
end)
edit: note that this event includes the player instance that clicked as a paramater
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
So would the script look like this?
local part = script.Parent local cd = part.ClickDetector cd.MouseClick:Connect(function(player) local re = game.ReplicatedStorage.ClickedButton function onClick() re:FireServer() end script.Parent.Mouseclick:Connect(onClick) end)
No. The script would look like how I showed it. It's that simple. You don't need to use FireServer for a remote event either if you put this in a normal script.