Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is wrong with my landmine trap? It disappears when I click play

Hello guys!

I am trying to get back into Roblox Scripting which I haven't touched in 5 months and I started off with a fun project. What I made is a special part that explodes when a player touches it.

Here is the code:

local trap = script.Parent

local function onTouch(part) 

--if part is player then local explosion = Instance.new("Explosion", trap) trap:Destroy() end

trap.Touched:connect(onTouch)

I forgot how to make it detect if the part touching the trap is a player so therefore it will go off when I run the game because it's touching the baseplate.

Any help would be appreciated. Thanks!

1 answer

This is the best I can do, if it does not work, I'll try my best to fix it, but here. This should work. All you have to do is put it into StarterPlayerScripts and a local script.

local trap = game.Workspace.Trap --change trap to the name
local plr = game.Players.LocalPlayer
function onTouch(part) 
local human = part.Parent:FindFirstChild("Humanoid")
if part.Parent.Name == plr.Name then
local explosion = Instance.new("Explosion", trap) 
wait(3) --change this to maybe 1 to make it fast
trap:Destroy() 
end

trap.Touched:connect(onTouch)

This discussion is preserved as it was. New answers, comments, and votes are closed.