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

onTouch script help?

Asked by 9 years ago

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!

1function onTouch(hit)
2    local f=Instance.new("Explosion")
3    f.Parent=script.Parent
4    f.BlastPressure=500
5    f.BlastRadius=500
6end
7 
8script.Parent.Touched:connect(onTouch)

2 answers

Log in to vote
1
Answered by
funyun 958 Moderation Voter
9 years ago

Simple, just set the position of the explosion to the part's position.

1f.Position=script.Parent.Position

Full script:

1function 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
6end
7 
8script.Parent.Touched:connect(onTouch)
0
Thanks so much! QuantumScripter 48 — 9y
Ad
Log in to vote
3
Answered by 9 years ago

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 
06db = true -- make db true
07function 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
17end
18 
19script.Parent.Touched:connect(onTouch)
0
I will never get debounce, it's too confusing... QuantumScripter 48 — 9y
1
basically the function can't run again until the last time it ran it has ran all the way through .. give me a moment and i'll break it down for you. magiccube3 115 — 9y
0
Add "end" on line 11, and maybe wait a bit before setting debounce back to true. funyun 958 — 9y
1
I saw the missing end thank you. I never use db so I forgot that we should probably wait. magiccube3 115 — 9y

Answer this question