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: Raycasting

Previous Thread :: Next Thread 
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
26 Apr 2013 08:04 PM
local tool = script.Parent
local user

tool.Equipped:connect(function(mouse)
user = tool.Parent
mouse.Button1Down:connect(function()
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(7)
end
local distance = (position - tool.Handle.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("White")
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)
game.Debris:AddItem(rayPart, 0.1)
end)
end)
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 11:58 AM
Bump.
Report Abuse
129K is not online. 129K
Joined: 23 Aug 2011
Total Posts: 19010
27 Apr 2013 12:01 PM
What's the problem?
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 12:11 PM
1. For some reason, it only works in LocalScript.
2. It doesn't hurt the humanoid.
Report Abuse
129K is not online. 129K
Joined: 23 Aug 2011
Total Posts: 19010
27 Apr 2013 12:16 PM
Then use a LocalScript.
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 12:19 PM
When I use LocalScript, it doesn't damage the humanoid.

When I use Script, it damages humanoid, but ray is not drawn.
Report Abuse
129K is not online. 129K
Joined: 23 Aug 2011
Total Posts: 19010
27 Apr 2013 12:20 PM
Try to make it cast more damage to the humanoid.
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 12:21 PM
What would that do? I tried it in build mode to monitor the Humanoid's health and it didn't go down at all.
Report Abuse
129K is not online. 129K
Joined: 23 Aug 2011
Total Posts: 19010
27 Apr 2013 12:22 PM
Try putting elses and prints around "if" statements.
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 02:21 PM
I said if the humanoid was hurt, print "Humanoid hurt!"

It printed, but it didn't work.
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 02:35 PM
Bump.
Report Abuse
getkoed2 is not online. getkoed2
Joined: 11 Apr 2010
Total Posts: 1144
27 Apr 2013 03:23 PM
I looked in the wiki for raycasting guns too and I found out :TakeDamage() might not work, so I changed it to humanoid.Health = humanoid.Health - 7

That did work
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 03:26 PM
Bump again, someone please help.
Report Abuse
ForceSky is not online. ForceSky
Joined: 30 Jul 2012
Total Posts: 2379
27 Apr 2013 03:28 PM
Ok, that's actually a good idea because I'm making a training area for my group.
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