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

What is this Explosion Position Error?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

So I created an exploding part that regens explode on contact.

When there is one, there is no problems at all, the script works perfectly from what I can tell, no errors. Proof: https://gyazo.com/3e57523d278005c8084db01dd2700ee5

However, when there are two of them, the new exploding part I copied and pasted messes up and doesn't position the explosion nor the rest of the script. The original exploding part proceeds to explode both of them. Proof: https://gyazo.com/f002e2d7a3e35f736b597dfcced4ffab

The script is located in game.Workspace.ExplodingPart

Any of ways to refine this script would be highly appreciated as well. I'm new to this so sorry if it seems disorganized.

-- Declarations
script.Parent.Anchored = true;
script.Parent.CanCollide = true;
ExplodingPart = game.Workspace.ExplodingPart;
local cooldown = 5;
local ExplosionEnable = true;

-- Explode Function
function Explode(part)
    local human = part.Parent:FindFirstChild("Humanoid");
    if ExplosionEnable ~= false and human ~= false then
        Instance.new("Explosion", script.Parent);
        ExplodingPart:WaitForChild("Explosion");
        ExplodingPart.Explosion.Position = script.Parent.Position;
        script.Parent.Transparency = 1;
        ExplosionEnable = false;
        script.Parent.CanCollide = false;
        wait(5);
        script.Parent.CanCollide = true;
        script.Parent.Transparency = 0;
        ExplosionEnable = true;
    end
end

-- Calling out the function "Explode"
script.Parent.Touched:connect(Explode)

1 answer

Log in to vote
0
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Here I fixed it for you... Also make sure this script is under both of the parts and both of the parts are named ExplodingPart

Here is the code I just fixed a few things you can check them out I added a Variable for explosion and all that... To make it a bit simpler...

script.Parent.Anchored = true;
script.Parent.CanCollide = true;
ExplodingPart = game.Workspace.ExplodingPart;
local cooldown = 5;
local ExplosionEnable = true;

function Explode(part)
    local human = part.Parent:FindFirstChild("Humanoid");
    if ExplosionEnable ~= false and human ~= false then
        local explosion = Instance.new("Explosion", script.Parent);
        explosion.Position = script.Parent.Position;
        script.Parent.Transparency = 1;
        ExplosionEnable = false;
        script.Parent.CanCollide = false;
        wait(5);
        script.Parent.CanCollide = true;
        script.Parent.Transparency = 0;
        ExplosionEnable = true;
    end
end

script.Parent.Touched:connect(Explode)

Ad

Answer this question