I have a part that when it touches another part or object it explodes but the explosion happens in the middle of the base plate and not on the part, help!
1 | function onTouch(hit) |
2 | local f = Instance.new( "Explosion" ) |
3 | f.Parent = script.Parent |
4 | f.BlastPressure = 500 |
5 | f.BlastRadius = 500 |
6 | end |
7 |
8 | script.Parent.Touched:connect(onTouch) |
Simple, just set the position of the explosion to the part's position.
1 | f.Position = script.Parent.Position |
Full script:
1 | function onTouch() --We won't need any arguments here. Just making an explosion. |
2 | local f = Instance.new( "Explosion" , script.Parent) --A shortcut to setting the explosion's Parent. |
3 | f.BlastPressure = 500 |
4 | f.BlastRadius = 500 |
5 | f.Position = script.Parent.Position |
6 | end |
7 |
8 | script.Parent.Touched:connect(onTouch) |
The above persons script makes sense since the explosion will occur at the scripts parents position, but they still need debounce.
01 | --First of all, debounce is just a variable, it's just a name for how we're using the variable. |
02 | --Debounce doesn't need to be named "debounce" it could be named anything! |
03 | --Ex: "thisisanokayname" "db" "wow" |
04 | --I'm going to use "db" |
05 |
06 | db = true -- make db true |
07 | function onTouch() |
08 | if db then -- if db is true then continue with the script |
09 | db = false -- set db to false so if the function is called before the function runs through all the way, it stops at the previous line |
10 | local f = Instance.new( "Explosion" , script.Parent) |
11 | f.BlastPressure = 500 |
12 | f.BlastRadius = 500 |
13 | f.Position = script.Parent.Position |
14 | wait(. 5 ) |
15 | db = true -- now the function can run again because db = true |
16 | end |
17 | end |
18 |
19 | script.Parent.Touched:connect(onTouch) |