generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Help making a laser pointer

Previous Thread :: Next Thread 
greatestdan is not online. greatestdan
Joined: 08 Sep 2008
Total Posts: 504
18 Feb 2012 04:48 PM
I am an average scripter and once I know how to use something I can make some good stuff with it. I have a new project I want to make.

It is simply a laser pointer. You hold down the mouse button and it makes a red laser pointing from the tool to where your cursor is. I know that it can and has been done before but i do not know how. Could someone tell me about some methods I could use to make this? I know it will involve Instance.new to create a block and then use LookVector (which I do not know how to use) or something like that to point it the correct way and find the distance between where the cursor is and the tool and change the size of the block to that.

Could someone give me a general lesson (that is the best word I can come up with) about how to do something like this? The only thing I really need help with is making it face the correct way, be the correct size (I know how to edit size but not how to make it the specific size it needs to be), and work when you hold down the mouse button (Is it something like Mouse.Hold?)

I am going to be looking at the wiki to find stuff but any help I can get from the forums will help.
Report Abuse
GrandAwsome is not online. GrandAwsome
Joined: 12 Jul 2011
Total Posts: 326
18 Feb 2012 04:54 PM
use CFrame(script.Parent.Handle,script.Parent.Parent.Humanoid.TargetPoint) to make it go the right direction
this would make the part face from the handle of the tool, to the TargetPoint


use script.Parent.Quipped:connect(function(mouse) to get the mouse

mouse.Button1Down:connect(function() to tell you when they made the mouse button go down

mouse.Button1Up:connect(function() to tell you when the mouse button went up

use magnitude to get the brick to be the right length
(position-position).magnitude

Instance.new("Part") will make the brick
Report Abuse
greatestdan is not online. greatestdan
Joined: 08 Sep 2008
Total Posts: 504
18 Feb 2012 05:11 PM
Here is what I got so far from that (I am not even trying the Magnitude thing for the size, just testing it so far.

How exactly would I use that CFrame(script.Parent.Handle,script.Parent.Parent.Humanoid.TargetPoint)?

This is my script so far

tool = script.Parent
handle = script.Parent.Handle

tool.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
p = Instance.new("Part")
p.Parent = script.Parent
p.BrickColor = BrickColor.new("Really red")
p.Name = "Laser"
p.CFrame(script.Parent.Handle,script.Parent.Parent.Humanoid.TargetPoint)
mouse.Button1Up:connect(function()
p:Remove()
end)
end)
end)
Report Abuse
GrandAwsome is not online. GrandAwsome
Joined: 12 Jul 2011
Total Posts: 326
18 Feb 2012 07:28 PM
tool.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
p = Instance.new("Part")
p.Parent = script.Parent
p.BrickColor = BrickColor.new("Really red")
p.Name = "Laser"
p.CFrame = CFrame.new(script.Parent.Handle,script.Parent.Parent.Humanoid.TargetPoint)
mouse.Button1Up:connect(function()
p:Remove()
end)
end)
end)


and then the size thing would be sort of like this:

p.Size = Vector3.new(script.Parent.Handle-script.Parent.Humanoid.TargetPoint).magnitude,1,1)
Report Abuse
GrandAwsome is not online. GrandAwsome
Joined: 12 Jul 2011
Total Posts: 326
18 Feb 2012 07:29 PM
and also, you probably want to change some of the properties of the laser such

p.BrickColor
p.Transparency
p.CanCollide
p.Reflectance
Report Abuse
greatestdan is not online. greatestdan
Joined: 08 Sep 2008
Total Posts: 504
18 Feb 2012 07:36 PM
p.CFrame = CFrame.new(script.Parent.Handle,script.Parent.Parent.Humanoid.TargetPoint)

it says this in output when I click

20:33:39 - Players.Player.Backpack.Tool.Script:15: bad argument #1 to 'new' (Vector3 expected, got userdata)
Report Abuse
GrandAwsome is not online. GrandAwsome
Joined: 12 Jul 2011
Total Posts: 326
19 Feb 2012 06:21 AM
sorry, forgot to put position

p.CFrame = CFrame.new(script.Parent.Handle.Position,script.Parent.Parent.Humanoid.TargetPoint)

Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
19 Feb 2012 07:19 AM
I made this ages ago :P

http://www.roblox.com/Laser-gun-item?id=42534365
Report Abuse
greatestdan is not online. greatestdan
Joined: 08 Sep 2008
Total Posts: 504
19 Feb 2012 12:11 PM
Here is script now

tool = script.Parent
handle = script.Parent.Handle

tool.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
p = Instance.new("Part")
p.Parent = script.Parent
p.BrickColor = BrickColor.new("Really red")
p.Name = "Laser"
p.FormFactor = "Custom"
p.Anchored = true
p.CanCollide = false
while true do
p.Size = Vector3.new(0.2, 0.2, (script.Parent.Handle.Position - script.Parent.Parent.Humanoid.TargetPoint).magnitude)
p.CFrame = CFrame.new(script.Parent.Handle.Position,script.Parent.Parent.Humanoid.TargetPoint)
end
end)
mouse.Button1Up:connect(function()
local search = tool:FindFirstChild("Laser")
if search ~= nil then
search:Remove()
end
end)
end)

When I use it it lags out the game!!!

At least in test mode. I will try uploading the place and testing it there
Report Abuse
greatestdan is not online. greatestdan
Joined: 08 Sep 2008
Total Posts: 504
20 Feb 2012 09:38 PM
Okay I fixed the lag out, the problem was I had no delay in the "while true do" which caused the game to crash.

But the problem now is that the laser continues the same distance on both sides of the tool, so it points correctly 1 way, then points the same amount the opposite direction. I know that I can add /2 after .magnitude to cut the size of it in half. i could probably do some stuff with meshes to get it right but if anyone knows a way to fix it (with how much I have explained it) please say so.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image