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

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago
Edited 6 years ago

: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

0
Didn't work QuantumScripter 48 — 6y
0
Workspace is removed after 5 seconds. GingeyLol 338 — 6y
0
didn't work QuantumScripter 48 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

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. jack8699 15 — 6y
0
Hey, there were no explosions and yes i changed the 0 values. QuantumScripter 48 — 6y
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. jack8699 15 — 6y
0
Still not working i'd really like to get this working... QuantumScripter 48 — 6y

Answer this question