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
 

Ray.new

Previous Thread :: Next Thread 
Shonysky is not online. Shonysky
Joined: 05 Aug 2013
Total Posts: 361
08 Dec 2013 03:17 PM
can someone help me to create a Ray in the game?
Report Abuse
Shonysky is not online. Shonysky
Joined: 05 Aug 2013
Total Posts: 361
08 Dec 2013 03:34 PM
bump *sadface*
Report Abuse
Shonysky is not online. Shonysky
Joined: 05 Aug 2013
Total Posts: 361
08 Dec 2013 03:40 PM
bump again
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
08 Dec 2013 03:41 PM
local tool = script.Parent
local user
--when the tool is equipped
tool.Equipped:connect(function(mouse)
--store the character of the person using the tool
user = tool.Parent

--when the left mouse button is clicked
mouse.Button1Down:connect(function()
--make and do a hit test along the ray
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*50)
local hit, position = game.Workspace:FindPartOnRay(ray, user)

--do damage to any humanoids hit
local humanoid = hit and hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(30)
end

--draw the ray
local distance = (position - tool.Handle.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright green")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, tool.Handle.CFrame.p) * CFrame.new(0, 0, -distance/2)

--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 0.4)
end)
end)

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