Making an onClicked script: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
minor cleanup
>KnKGames.Com
No edit summary
Line 1: Line 1:
==Introduction==
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
I am permantly banned from roblox!


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.
Please Spread The Word!


==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.


==Getting Started==
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
I am permantly banned from roblox!


First things first, you have to put the ClickDetector inside the brick.  Click on the brick, then click on 'Insert" on the toolbar and then click on "Object".  Then look for "Click Detector" in the window that pops up.  You now have your Click Detector.  Now, put in a script.
Please Spread The Word!


==The Script==
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
Here is the first part of the scripting:
I am permantly banned from roblox!


  function onClicked()
Please Spread The Word!


This tells the game to set off the function when the brick is clicked on.
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
Next we have to put in the function (this is only an example, so feel free to change this part if you want)
I am permantly banned from roblox!
 
  local x = (math.random(0,10) * 0.1)
  local y = (math.random(0,10) * 0.1)
  local z = (math.random(0,10) * 0.1)
  script.Parent.Color = Color3.new (x, y, z)


This tells the game to change the block's color to a random color.
Please Spread The Word!


Finally, you need to 'connect' the script.
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
I am permantly banned from roblox!


  script.Parent.ClickDetector.MouseClick:connect(onClicked)
Please Spread The Word!
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
I am permantly banned from roblox!


The finished script should look like this:
Please Spread The Word!
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
I am permantly banned from roblox!


  function onClicked()
Please Spread The Word!
  local x = (math.random(0,10) * 0.1)
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
  local y = (math.random(0,10) * 0.1)
I am permantly banned from roblox!
  local z = (math.random(0,10) * 0.1)
  script.Parent.Color = Color3.new (x, y, z)
  end
 
  script.Parent.ClickDetector.MouseClick:connect(onClicked)


Please Spread The Word!
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
I am permantly banned from roblox!


==Finding Clicker==
Please Spread The Word!
Even though ClickDetector doesn't have any function arguements so you can't tell who clicked it, it is possible. This is how:
Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
===Method 1===
I am permantly banned from roblox!
This will make it so only one person can click it:


1.Make a part. Name it what you like
Please Spread The Word!Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details!
2.Put in 2 Scripts. Name one "CheckScript" and the other "MakeScript"
I am permantly banned from roblox!
3.Insert a StringValue. Name it "Owner". Change the value to who you want to click on it.
4.Put a ClickDetector into the part, set the MaxActivationDistance to 0
5.In the "CheckScript", paste this:
<pre>
dist = 10 --change this to how far away you can be


while true do
Please Spread The Word!
wait(1)
local p = game.Players:GetChildren()
for i = 1, #p do
if (p[i].Name == script.Parent.Owner.Value) then
if (game.Workspace:findFirstChild(p[i].Name) ~= nil) then
if (p[i].Character.Torso.Position - script.Parent.Position).magnitude < dist then
script.Parent.ClickDetector.MaxActivationDistance = dist
else
script.Parent.ClickDetector.MaxActivationDistance = 0
end
end
end
end </pre>
6.In the "MakeScript", paste this:
<pre>
dist = 10 --change this to how far away you can be
 
function onClicked()
local p = game.Players:GetChildren()
for i = 1, #p do
if (p[i].Name == script.Parent.Owner.Value) then
if (p[i].Character.Torso.Position - script.Parent.Position).magnitude < dist then
--Put Stuff Here
end
end
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked) </pre>
Now it should do what you put after "--Put Stuff Here" in the "MakeScript" to the person who is in the owner value.
 
===Method 2===
This method will make it so only a team can click on it.
1.Make a part. Name it what you like
2.Put in 2 Scripts. Name one "CheckScript" and the other "MakeScript"
3.Put a ClickDetector into the part, set the MaxActivationDistance to 0
4.In the "CheckScript", paste this:
<pre>
dist = 10 --change this to how far away you can be
teamcolor = BrickColor.new(21> --change this to the team
 
while true do
wait(1)
local p = game.Players:GetChildren()
for i = 1, #p do
if (p[i].TeamColor == teamcolor) then
if (game.Workspace:findFirstChild(p[i].Name) ~= nil) then
if (p[i].Character.Torso.Position - script.Parent.Position).magnitude < dist then
script.Parent.ClickDetector.MaxActivationDistance = 10
else
script.Parent.ClickDetector.MaxActivationDistance = 0
end
end
end
end
end </pre>
5.In the "MakeScript", paste this:
<pre>
dist = 10 --change this to how far away you can be
teamcolor = BrickColor.new(21> --change this to the team
 
function onClicked()
local p = game.Players:GetChildren()
for i = 1, #p do
if (p[i].TeamColor == teamcolor) then
if (p[i].Character.Torso.Position - script.Parent.Position).magnitude < dist then
--Put Stuff Here
end
end
end
end
 
script.Parent.ClickDetector.MouseClick:connect(onClicked) </pre>
Now it should do what you put after "--Put Stuff Here" in the "MakeScript" to the person/team.

Revision as of 06:13, 2 July 2008

Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word!


Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word!

Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word!

Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word!

Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word! Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word! Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word! Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word! Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word! Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word!Attention Everyone: I did not phish Roni123’s acount! Someone hacked knkgames.com! Talk to Roni123 for more details! I am permantly banned from roblox!

Please Spread The Word!