Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Do i put this script in the block or in the click detector?

Here is the script:

local re = game.ReplicatedStorage.ClickedButton 

function onClick()
    re:FireServer()
end

script.Parent.MouseButton1Down:Connect(onClick)

1 answer

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

3 comments

0

So would the script look like this?

0

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)

0

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.