Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Would this bullet script work?

Asked by 10 years ago

I was just wanting to know if this script would work or not.

ball = script.Parent
local invelocity = ball.Velocity
wait()

function onTouched(hit)
        local human = hit.Parent:findFirstChild("Humanoid")
    if (human ~= nil) then
        human.Health = human.Health - 25  --How much damage the brick does when touched. (100=death when health is normal)
    end
end
script.Parent.Touched:connect(onTouched)

connection = script.Parent.Touched:connect(onTouched)



wait(0.5)

ball.Parent = nil

1 answer

Log in to vote
1
Answered by
jav2612 180
10 years ago

That script would work, although you should probably remove the bullet after it hits someone instead of after 0.5 seconds. That way it won't if it hasn't hit anyone yet. You can also add a timeout so if it never hits anyone it gets removed too, but 0.5 seconds seems too short.

I'm not sure why you made the connection a variable. The only use of that would be if you wanted to disconnect the event later in the script.

Also you should use :Destroy() instead of parenting things to nil to get rid of them.

This would be a more efficient script:


ball = script.Parent local invelocity = ball.Velocity wait() Game:GetService("Debris"):AddItem(ball, 10) -- you could just add wait(10) ball:Destroy() at the end of the script but I think this is fancier :3 function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then human.Health = human.Health - 25 --How much damage the brick does when touched. (100=death when health is normal) ball:Destroy() end end script.Parent.Touched:connect(onTouched) connection = script.Parent.Touched:connect(onTouched)
0
Alright. Thanks. Can you help on that? TheRings0fSaturn 28 — 10y
0
Also, I have another script in my Laser gun that removes the ball after a couple seconds. TheRings0fSaturn 28 — 10y
0
In that case you should get rid of one of the methods to remove the ball. Either get rid of the part that removed it in the lazer or remove the Debris part in this script. jav2612 180 — 10y
Ad

Answer this question