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 8 years ago
Edited 8 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

01local ExplosionPart = Instance.new('Part',workspace)
02ExplosionPart.CFrame = script.Parent.CFrame
03ExplosionPart.Anchored = true
04ExplosionPart.CanCollide = false
05ExplosionPart.Size = Vector3.new(1,1,1)
06ExplosionPart.BrickColor = BrickColor.new('Really black')
07ExplosionPart.Material = 'Neon'
08ExplosionPart.Transparency = 0.5
09ExplosionPart.Shape = 'Ball'
10 
11local start = ExplosionPart.Size
12local finish = ExplosionPart.Size * Vector3.new(2,2,2)
13 
14 
15local disipate = script.DisipateEffect:Clone()
View all 24 lines...

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

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

1 answer

Log in to vote
0
Answered by 8 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.

01local ExplosionPart = Instance.new('Part',workspace)
02 
03ExplosionPart.Anchored = true
04ExplosionPart.CanCollide = false
05ExplosionPart.Size = Vector3.new(1,1,1)
06ExplosionPart.BrickColor = BrickColor.new('Really black')
07ExplosionPart.Material = 'Neon'
08ExplosionPart.Transparency = 0.5
09ExplosionPart.Shape = 'Ball'
10 
11ExplosionPart.CFrame = script.Parent.CFrame -- moved this line to AFTER all the properties are set
12 
13local start = ExplosionPart.Size
14local finish = ExplosionPart.Size * Vector3.new(2,2,2)
15 
View all 26 lines...
Ad

Answer this question