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

Maing an explosion where part was touched?

Asked by 7 years ago
Edited 7 years ago

So i made this script that is saposed to make an explosion effect wherever the 2 parts collide

I have an on touched script that clones the following script into whatever is touching the part, in this case a players body part, whenever you or a npc touches the player an explosion part will appear whereever the 2 parts touched

The problem is that sometimes when i touch another humanoid the explosions would appear over my should if something were to touch on of my legs

local ExplosionPart = Instance.new('Part',workspace)
ExplosionPart.CFrame = script.Parent.CFrame
ExplosionPart.Anchored = true
ExplosionPart.CanCollide = false
ExplosionPart.Size = Vector3.new(1,1,1)
ExplosionPart.BrickColor = BrickColor.new('Really black')
ExplosionPart.Material = 'Neon'
ExplosionPart.Transparency = 0.5
ExplosionPart.Shape = 'Ball'

local start = ExplosionPart.Size
local finish = ExplosionPart.Size * Vector3.new(2,2,2)


local disipate = script.DisipateEffect:Clone()
disipate.Parent = ExplosionPart
disipate.Disabled = false

    for progress = 0, 1, 0.03 do
        ExplosionPart.Size = start:lerp(finish, progress)
        wait()
    end     

script:Destroy()

Here is the script that clones the script above into the part that touched the players body part

function onDamage(Part)--function to cause damage to those hit with fireball
    if Part.Parent:FindFirstChild("Humanoid") ~=nil and Part.Parent.Name ~= "script.Parent.Name" then--If the thing is humanoid then
        script.Disabled = false
        local effect = script.GiantEffect:Clone()
        effect.Parent = Part
        effect.Disabled = false         
        Part.Parent.Humanoid:TakeDamage(45)
        print('DAMAGED')
    end--end the second argument of code chunk
end--end the thrid argument of code chunk
script.Parent.Touched:connect(onDamage)

1 answer

Log in to vote
0
Answered by 7 years ago

Try this - edit the CFrame of Explosionpart LAST. I think that what's happening is when you edit Size AFTER you edit CFrame, the part gets moved because of a collision check that happens when Size gets edited.

local ExplosionPart = Instance.new('Part',workspace)

ExplosionPart.Anchored = true
ExplosionPart.CanCollide = false
ExplosionPart.Size = Vector3.new(1,1,1)
ExplosionPart.BrickColor = BrickColor.new('Really black')
ExplosionPart.Material = 'Neon'
ExplosionPart.Transparency = 0.5
ExplosionPart.Shape = 'Ball'

ExplosionPart.CFrame = script.Parent.CFrame -- moved this line to AFTER all the properties are set

local start = ExplosionPart.Size
local finish = ExplosionPart.Size * Vector3.new(2,2,2)


local disipate = script.DisipateEffect:Clone()
disipate.Parent = ExplosionPart
disipate.Disabled = false

    for progress = 0, 1, 0.03 do
        ExplosionPart.Size = start:lerp(finish, progress)
        wait()
    end     

script:Destroy()


Ad

Answer this question