<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Making_an_onClicked_script</id>
	<title>Making an onClicked script - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.starfall.wtf/index.php?action=history&amp;feed=atom&amp;title=Making_an_onClicked_script"/>
	<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Making_an_onClicked_script&amp;action=history"/>
	<updated>2026-07-28T16:13:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.starfall.wtf/index.php?title=Making_an_onClicked_script&amp;diff=412&amp;oldid=prev</id>
		<title>PRG: Created page with &quot;{{CatUp|Tutorials}} __TOC__  ==Introduction==  This is a FAQ that will teach you how to make a simple onClicked script.  This FAQ will also explain how to put it to use.  ==What is onClicked?==  Not long ago, Roblox released a new feature known as a Click Detector.  If you put it inside a brick it will detect when it is clicked.  == Instructions ==  1) Insert a brick onto your map.&lt;br&gt; 2) Insert -&gt; Object -&gt; ClickDetector inside that same brick.&lt;br&gt; 3) Insert a script in...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.starfall.wtf/index.php?title=Making_an_onClicked_script&amp;diff=412&amp;oldid=prev"/>
		<updated>2024-12-10T12:46:26Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{CatUp|Tutorials}} __TOC__  ==Introduction==  This is a FAQ that will teach you how to make a simple onClicked script.  This FAQ will also explain how to put it to use.  ==What is onClicked?==  Not long ago, Roblox released a new feature known as a Click Detector.  If you put it inside a brick it will detect when it is clicked.  == Instructions ==  1) Insert a brick onto your map.&amp;lt;br&amp;gt; 2) Insert -&amp;gt; Object -&amp;gt; ClickDetector inside that same brick.&amp;lt;br&amp;gt; 3) Insert a script in...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{CatUp|Tutorials}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
This is a FAQ that will teach you how to make a simple onClicked script.  This FAQ will also explain how to put it to use.&lt;br /&gt;
&lt;br /&gt;
==What is onClicked?==&lt;br /&gt;
&lt;br /&gt;
Not long ago, Roblox released a new feature known as a Click Detector.  If you put it inside a brick it will detect when it is clicked.&lt;br /&gt;
&lt;br /&gt;
== Instructions ==&lt;br /&gt;
&lt;br /&gt;
1) Insert a brick onto your map.&amp;lt;br&amp;gt;&lt;br /&gt;
2) Insert -&amp;gt; Object -&amp;gt; ClickDetector inside that same brick.&amp;lt;br&amp;gt;&lt;br /&gt;
3) Insert a script inside that same brick, but not inside ClickDetector.&amp;lt;br&amp;gt;&lt;br /&gt;
4) Double-click the script, and insert the following:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  function onClicked()&lt;br /&gt;
  	local x = (math.random(0,10) * 0.1)&lt;br /&gt;
  	local y = (math.random(0,10) * 0.1)&lt;br /&gt;
  	local z = (math.random(0,10) * 0.1)&lt;br /&gt;
  	script.Parent.Color = Color3.new (x, y, z)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  script.Parent.ClickDetector.MouseClick:connect(onClicked)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The Script==&lt;br /&gt;
Here is the first part of the scripting:&lt;br /&gt;
&lt;br /&gt;
  function onClicked()&lt;br /&gt;
&lt;br /&gt;
This tells the game to set off the function when the brick is clicked on.&lt;br /&gt;
(This is only an example, so feel free to change this part if you want)&lt;br /&gt;
  &lt;br /&gt;
  	local x = (math.random(0,10) * 0.1)&lt;br /&gt;
  	local y = (math.random(0,10) * 0.1)&lt;br /&gt;
  	local z = (math.random(0,10) * 0.1)&lt;br /&gt;
  	script.Parent.Color = Color3.new (x, y, z)&lt;br /&gt;
&lt;br /&gt;
This tells the game to change the block&amp;#039;s color to a random color.&lt;br /&gt;
&lt;br /&gt;
Finally, the script is &amp;#039;connected&amp;#039;:&lt;br /&gt;
&lt;br /&gt;
  script.Parent.ClickDetector.MouseClick:connect(onClicked)&lt;br /&gt;
&lt;br /&gt;
==Finding Clicker==&lt;br /&gt;
Even though ClickDetector doesn&amp;#039;t have any function arguements so you can&amp;#039;t tell who clicked it, it is possible. This is how:&lt;br /&gt;
===Method 1===&lt;br /&gt;
This will make it so only one person can click it:&lt;br /&gt;
&lt;br /&gt;
*1.Make a part. Name it what you like&lt;br /&gt;
*2.Put in 2 Scripts. Name one &amp;quot;CheckScript&amp;quot; and the other &amp;quot;MakeScript&amp;quot;&lt;br /&gt;
*3.Insert a StringValue. Name it &amp;quot;Owner&amp;quot;. Change the value to who you want to click on it.&lt;br /&gt;
*4.Put a ClickDetector into the part, set the MaxActivationDistance to 0&lt;br /&gt;
*5.In the &amp;quot;CheckScript&amp;quot;, paste this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dist = 10 --change this to how far away you can be&lt;br /&gt;
&lt;br /&gt;
while true do&lt;br /&gt;
wait(1)&lt;br /&gt;
local p = game.Players:GetChildren()&lt;br /&gt;
for i = 1, #p do&lt;br /&gt;
if (p[i].Name == script.Parent.Owner.Value) then&lt;br /&gt;
if (game.Workspace:findFirstChild(p[i].Name) ~= nil) then&lt;br /&gt;
if (p[i].Character.Torso.Position - script.Parent.Position).magnitude &amp;lt; dist then&lt;br /&gt;
script.Parent.ClickDetector.MaxActivationDistance = dist&lt;br /&gt;
else&lt;br /&gt;
script.Parent.ClickDetector.MaxActivationDistance = 0&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
end &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
6.In the &amp;quot;MakeScript&amp;quot;, paste this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dist = 10 --change this to how far away you can be&lt;br /&gt;
&lt;br /&gt;
function onClicked()&lt;br /&gt;
	local p = game.Players:GetChildren()&lt;br /&gt;
	for i = 1, #p do&lt;br /&gt;
		if (p[i].Name == script.Parent.Owner.Value) then&lt;br /&gt;
			if (p[i].Character.Torso.Position - script.Parent.Position).magnitude &amp;lt; dist then&lt;br /&gt;
			print(&amp;quot;Hello world!&amp;quot;)  -- this is just an example&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
script.Parent.ClickDetector.MouseClick:connect(onClicked) &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can simply replace print(&amp;quot;Hello world!&amp;quot;) with whatever you want this to do.&lt;br /&gt;
&lt;br /&gt;
===Method 2===&lt;br /&gt;
This method will make it so only a team can click on it.&lt;br /&gt;
&lt;br /&gt;
1.Make a part. Name it what you like.&amp;lt;br&amp;gt;&lt;br /&gt;
2.Put in 2 Scripts. Name one &amp;quot;CheckScript&amp;quot; and the other &amp;quot;MakeScript&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
3.Put a ClickDetector into the part, set the MaxActivationDistance to 0&amp;lt;br&amp;gt;&lt;br /&gt;
4.In the &amp;quot;CheckScript&amp;quot;, paste this:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dist = 10 --change this to how far away you can be&lt;br /&gt;
teamcolor = BrickColor.new(&amp;quot;Bright yellow&amp;quot;) --change this to the team&lt;br /&gt;
&lt;br /&gt;
while true do&lt;br /&gt;
wait(1)&lt;br /&gt;
local p = game.Players:GetChildren()&lt;br /&gt;
	for i = 1, #p do&lt;br /&gt;
		if (p[i].TeamColor == teamcolor) then&lt;br /&gt;
			if (game.Workspace:findFirstChild(p[i].Name) ~= nil) &lt;br /&gt;
			then&lt;br /&gt;
				if (p[i].Character.Torso.Position - script.Parent.Position).magnitude &amp;lt; dist &lt;br /&gt;
				then &lt;br /&gt;
				script.Parent.ClickDetector.MaxActivationDistance = 10&lt;br /&gt;
				else&lt;br /&gt;
				script.Parent.ClickDetector.MaxActivationDistance = 0&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end &amp;lt;/pre&amp;gt;&lt;br /&gt;
5.In the &amp;quot;MakeScript&amp;quot;, paste this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dist = 10 --change this to how far away you can be&lt;br /&gt;
teamcolor = BrickColor.new(&amp;quot;Bright yellow&amp;quot;)  --change this to the team&lt;br /&gt;
&lt;br /&gt;
function onClicked()&lt;br /&gt;
&lt;br /&gt;
	local p = game.Players:GetChildren()&lt;br /&gt;
	for i = 1, #p do&lt;br /&gt;
		if (p[i].TeamColor == teamcolor) then&lt;br /&gt;
			if (p[i].Character.Torso.Position - script.Parent.Position).magnitude &amp;lt; dist then&lt;br /&gt;
				print(&amp;quot;Hello world!&amp;quot;)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
script.Parent.ClickDetector.MouseClick:connect(onClicked)  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change print(&amp;quot;Hello world!&amp;quot;) to whatever you want.&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;/div&gt;</summary>
		<author><name>PRG</name></author>
	</entry>
</feed>