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

How to make this part explode only when it collides with objects?

Asked by 6 years ago
Edited 6 years ago

I made a script where the part explodes when it collides with anything. How do I make so it only explodes when touching the objects, not with players?

Here's my script;

function onTouched(hit) 
    local e = Instance.new("Explosion") 

    e.BlastRadius = 15 

    e.BlastPressure = 1000

    e.Parent = game.Workspace 

    e.Position = script.Parent.Position 
end

script.Parent.Touched:connect(onTouched)
0
check that hit.Parent does not contain a humanoid User#5423 17 — 6y
0
What do you mean by that? ShadowNinja1080 6 — 6y
0
Check if hit.Parent has 'Humanoid' in an if statement at the beginning of the function. Viking359 161 — 6y
0
if humanoid then end if not humanoid then local e... greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
6 years ago

Add a check for humanoids. Also, add a debounce to not lag the player's game.

local debounce = true
function onTouched(hit) 
if hit.Parent:FindFirstChild("Humanoid") then
print('Humanoid found.')
else
    if debounce == true then
        debounce = false
        local e = Instance.new("Explosion") 

         e.BlastRadius = 15 

         e.BlastPressure = 1000

         e.Parent = game.Workspace 

         e.Position = script.Parent.Position
            wait(1)
            debounce = true
    else
        print('deb is false lolololol')
        end
    end 
end

script.Parent.Touched:connect(onTouched)

Ad

Answer this question