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: Raycast is not doing damage..

Previous Thread :: Next Thread 
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
23 Feb 2013 02:09 PM
local startpoint=Tool[BarrelName].CFrame.p
local mag=(mouse.Hit.p-startpoint).magnitude
local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag, (Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))
local ray = Ray.new(Tool[BarrelName].CFrame.p , (mouse.Hit.p+ rndm - Tool[BarrelName].CFrame.p).unit*999.999)
local objHit, objPosition = game.Workspace:FindPartOnRay(ray, User)
print(objHit, objPosition)
objHit = objHit -- adasd lol
local humanoid = objHit and objHit.Parent:findFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(BaseDamage)
end
local endpoint = (objPosition - Tool[BarrelName].CFrame.p).magnitude
local rayPart = Instance.new("Part", game.Workspace)
rayPart.Name = "Bullet"
rayPart.BrickColor = RayColor
rayPart.Transparency = 0
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, endpoint)
rayPart.CFrame = CFrame.new(objPosition, Tool[BarrelName].CFrame.p) * CFrame.new(0, 0, -endpoint/2)



Sometimes objHit is returned nil..
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
23 Feb 2013 02:11 PM
Where did you define BaseDamage? Put a print after humanoid:TakeDamage(BaseDamage) to make sure the check for the humanoid passes.
Report Abuse
pwnedu46 is not online. pwnedu46
Joined: 23 May 2009
Total Posts: 7534
23 Feb 2013 02:12 PM
"objHit and objHit.Parent:findFirstChild("Humanoid") "

This is why. This line will make humanoid a boolean value instead of the Humanoid object you want.
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
23 Feb 2013 02:12 PM
I fixed it somehow..

I just added if objHit then

and added humanoid.Health = humanoid.Health - BaseDamage


what..
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
23 Feb 2013 02:24 PM
everytime objHit returns nil, it crashes the player.

How can I stop this?
Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
23 Feb 2013 02:25 PM
I can barely read your code because there are no spaces...
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
23 Feb 2013 02:26 PM
local objHit, objPosition = game.Workspace:FindPartOnRay(ray, User)

print(objHit, objPosition)

wait(1)

if objHit ~= nil then

wait()

local humanoid = objHit.Parent:findFirstChild("Humanoid")

if humanoid then

wait()

humanoid.Health= humanoid.Health - math.random(1,BaseDamage)

end

Report Abuse
thedestroyer115 is not online. thedestroyer115
Joined: 19 Dec 2010
Total Posts: 11546
23 Feb 2013 02:27 PM
That wouldn't crash anything unless you have a loop somewhere.
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
23 Feb 2013 02:28 PM
while Equipped == true and Down == true and script.Ammo.Value >= 1 do

if deb == false then deb = true

firing = true

Tool.Handle.Fire:Play()

script.Ammo.Value = script.Ammo.Value - 1

player.PlayerGui:findFirstChild("objGui").Ammo.Text = script.Ammo.Value.."/"..MaxAmmo

local startpoint=Tool[BarrelName].CFrame.p

local mag=(mouse.Hit.p-startpoint).magnitude

local rndm=Vector3.new(math.random(-(Spread/10)*mag,(Spread/10)*mag),math.random(-(Spread/10)*mag, (Spread/10)*mag),math.random(-(Spread/10)*mag,(Spread/10)*mag))

local ray = Ray.new(Tool[BarrelName].CFrame.p , (mouse.Hit.p+ rndm - Tool[BarrelName].CFrame.p).unit*999.999)

local objHit, objPosition = game.Workspace:FindPartOnRay(ray, User)

print(objHit, objPosition)

wait()

local humanoid = objHit.Parent:findFirstChild("Humanoid")

if humanoid then

wait()

humanoid.Health= humanoid.Health - math.random(1,BaseDamage)

end
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
23 Feb 2013 02:29 PM
LOL.

I put wait() in the wrong spot..
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