This script is inside a turret. This is the ammo script. I don't care about the damage player stuff because i won't be using this on a player so you can take that out.
ball = script.Parent damage = 50 function onTouched(hit) local humanoid = hit.Parent:findFirstChild("Humanoid") if humanoid ~= nil then humanoid:TakeDamage(damage) local explosion = Instance.new("Explosion", ball) explosion.Position = ball.Position ball:Remove() end end connection = ball.Touched:connect(onTouched) wait(5) ball.Parent = nil
:findFirstChild > :FindFirstChild
if hit.Parent:fFindFirstChild("Humanoid")~= nil then
:Remove() is deprecated use :Destroy
use :Connect
local explosion = Instance.new("Explosion", ball) is deprecated instead use another line of code to parent it
local explosion = Instance.new("Explosion") explosion.Parent = ball
you didn't do wait() so once the ball is instanced and created it removes itself
local explosion = Instance.new("Explosion", ball) explosion.Position = ball.Position wait(5) --time ball:Destroy()
also be aware that after 5 seconds the balls parent will be nil meaning that the ball Parent which is most likely Workspace will be REMOVED
Also this infinitely loads whenever the part is touched
Hi QuantumScripter,
So it looks like what you're trying to do is make an explosion when you touch a part that removes 50 health and then removes ball when it's done.
Everything that GingeyLol said was correct and he basically showed you how to fix your script.
If you wanted to know how to correctly do what you want to do then personally this is how I would do it
ball = script.Parent damage = 50 db = true script.Parent.Touched:connect(function(hit) if db == true then db = false local humanoid = hit.Parent:findFirstChild("Humanoid") if humanoid ~= nil then humanoid:TakeDamage(damage) local explosion = Instance.new("Explosion", workspace) explosion.Position = ball.Position explosion.BlastPressure = 0 -- so you dont explode explosion.BlastRadius = 0 -- so you dont explode wait() -- so the ball won't get destroyed before the explosion happens ball:Destroy() end end wait(1) db = true end) wait(5) ball.Parent = nil
If anybody finds something that can be fixed in the script I'm showing then tell me please.