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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 23 Feb 2013 02:25 PM |
| I can barely read your code because there are no spaces... |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 23 Feb 2013 02:27 PM |
| That wouldn't crash anything unless you have a loop somewhere. |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 18 Feb 2011 |
| Total Posts: 22763 |
|
|
| 23 Feb 2013 02:29 PM |
LOL.
I put wait() in the wrong spot.. |
|
|
| Report Abuse |
|
|