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

Run a script with a clickdetector?

I want to make it so the clickdetector runs a different script. However I am new and don't know where to start.

2 comments

0

Please elaborate

0

You need to give us more information on your problem. I cant tell what the problem is.

1 answer

I'm assuming you mean when you click a part it runs another script if so then this is the answer.

SETUP: First, you would need a remote event for the two scripts to communicate with each other. To do this you simply go into ReplicatedStorage and add a new RemoteEvent and call it ( MyRemoteEvent )

This first script is going to be in your part:

local part = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")

part.ClickDetector.MouseClick:Connect(function() -- When someone clicks the part it runs this code below
	
	local MyRemoteEvent = ReplicatedStorage:WaitForChild("MyRemoteEvent") -- getting the remoteevent that you made previusly
	
	MyRemoteEvent:FireServer() -- Activates the event so the other script knows when to start going.
	
end)

This is the other script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local MyRemoteEvent = ReplicatedStorage:WaitForChild("MyRemoteEvent") -- The RemoteEvent you made previusly

MyRemoteEvent.OnServerEvent:Connect(function() -- When the first script is touched this code under will run
	
	-- From here you just put your code in here and it should work
	
end)

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

if this helped you please accept my answer :D

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