Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I've done everything correctly and no error messages but this script still isn't working?

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

2 answers

: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

3 comments

0

Didn't work

0

Workspace is removed after 5 seconds.

0

didn't work

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.

4 comments

0

Also, I'm not sure what you're trying to do with wait(5) ball.Parent = nil. if the ball.Parent is workspace than that can destroy workspace.

0

Hey, there were no explosions and yes i changed the 0 values.

0

That's very weird, it works properly when I did it. Either you might not of copy and pasted it correctly or it might be something to do with your studio settings.

0

Still not working i'd really like to get this working...

This discussion is preserved as it was. New answers, comments, and votes are closed.