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

Run a script with a clickdetector?

Asked by 3 years ago

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

0
Please elaborate Soban06 410 — 3y
0
You need to give us more information on your problem. I cant tell what the problem is. JustinWe12 723 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

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

Ad

Answer this question