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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
Ad

Answer this question