--[[
	I should note that this works
	amazingly in third person, but
	not so much in first person.
--]]


debounce = true
local trap = script.Parent.Parent

function onTouched(i)
	local h = i.Parent:findFirstChild("Humanoid")
	if (h ~= nil and debounce == true) then --If the part is a player then
		if script.Parent.Captured.Value == false then
			debounce = false
			h.Health = h.Health - h.Health/100 --Take all of the player's health away
			i.Parent["Right Leg"].Anchored = true --Anchor their legs
			i.Parent["Left Leg"].Anchored = true
			trap.Open.Transparency = 1 --Close the trap
			trap.Close.Transparency = 0
			script.Parent.Bang:Play() --Play audios
			script.Parent.Ow:Play()
			wait(0.5)
			i.Parent.Torso.Anchored = true --Anchor their torso so they don't flail around
			script.Parent.Captured.Value = true
			wait(3) --Wait 3 seconds
			script.Parent.ClickDetector.MaxActivationDistance = 16 --Make it so that you can set up the trap again
			i.Parent["Right Leg"].Anchored = false --Free the player
			i.Parent["Left Leg"].Anchored = false
			h.Jump = true --Make sure the player isn't glitched
			i.Parent.Torso.Anchored = false
			debounce = true
		end
	end
end

script.Parent.Touched:connect(onTouched)
