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

onTouch script help?

Asked by 8 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!

function onTouch(hit)
    local f=Instance.new("Explosion")
    f.Parent=script.Parent
    f.BlastPressure=500
    f.BlastRadius=500
end

script.Parent.Touched:connect(onTouch)

2 answers

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

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

f.Position=script.Parent.Position

Full script:

function onTouch() --We won't need any arguments here. Just making an explosion.
    local f=Instance.new("Explosion", script.Parent) --A shortcut to setting the explosion's Parent.
    f.BlastPressure=500
    f.BlastRadius=500
    f.Position=script.Parent.Position
end

script.Parent.Touched:connect(onTouch)

0
Thanks so much! QuantumScripter 48 — 8y
Ad
Log in to vote
3
Answered by 8 years ago

The above persons script makes sense since the explosion will occur at the scripts parents position, but they still need debounce.

--First of all, debounce is just a variable, it's just a name for how we're using the variable.
--Debounce doesn't need to be named "debounce" it could be named anything!
--Ex: "thisisanokayname" "db" "wow"
--I'm going to use "db"

db = true -- make db true
function onTouch()
    if db then -- if db is true then continue with the script
    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
    local f=Instance.new("Explosion", script.Parent)
    f.BlastPressure=500
    f.BlastRadius=500
    f.Position=script.Parent.Position
    wait(.5)
    db = true -- now the function can run again because db = true
    end
end

script.Parent.Touched:connect(onTouch)
0
I will never get debounce, it's too confusing... QuantumScripter 48 — 8y
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 — 8y
0
Add "end" on line 11, and maybe wait a bit before setting debounce back to true. funyun 958 — 8y
1
I saw the missing end thank you. I never use db so I forgot that we should probably wait. magiccube3 115 — 8y

Answer this question