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

Create a ClickDetector from a script?

Asked by
Cuvette 246 Moderation Voter
8 years ago

Basically what the title says, I've seen nothing about it being possible but I need to create a ClickDetector from a script rather than adding it manually from studio, is there a solution to that?

2 answers

Log in to vote
2
Answered by 8 years ago

Hi there!

Seems like you're new here! and Welcome!

So, to your question, "Create a ClickDetector from a script" ok dude, here you go

Now, in ROBLOX there is a method of creating new GameObjects(parts, scripts, decals, guis etc)

You can create a simple part via a script like this local part = Instance.new("Part", workspace)

Syntax

It's simple, All you need to do is mention which object you want to create it, and then where you want to create it!

scope variable_name = Instance.new(object, parent)

Now in the above syntax, ~ Scope means if a variable is local or global, If you set it to local, it will only be accessed in that block of code, for example, if you define it in a "Function" then it will only be accessed in that function. A global scope can be accessed from anywhere from inside the 'script' object.

~ variable_name is the name of the variable you want to set the object to, so you can use it anywhere else!

~ object is the object you want to create, in this case, it's "ClickDetector" ~ parent is the object to which you want to have the object(ClickDetector) as child.

Welp! Hope that helps!

here's some reference you may wanna check http://wiki.roblox.com/index.php?title=API:Class/ClickDetector http://wiki.roblox.com/index.php?title=Cookbook_(Chapter_1)#Creating_a_clickable_part

adios!

0
Yeah I'm definitely not new here, It's a newbie question but I couldn't find anything on the Wiki about it, but thanks for the answer I completely forget you could insert objects that way! Cuvette 246 — 8y
0
Great! buoyantair 123 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

Read the roblox wiki . It will help you learn how to do this yourself. But since you asked. @M39a9am3R says that click detectors don't work with filtering enabled. Here is a link to fix that

You can create a new instance of it.

ClickDetector = Instance.new("ClickDetector",game.workspace)

If you want it in a part.

 ClickDetector = Instance.new("ClickDetector",game.Workspace.Part) -- edit the name of Part to what your part is called.

Answer this question