Spike Wall

Script

local trigger = script.Parent

local wall_1 = game.Workspace.Wall1

local stop_1 = game.Workspace.Wall1_Stop.Position

local wall_2 = game.Workspace.Wall2

local stop_2 = game.Workspace.Wall2_Stop.Position

local trap_activated = false

local wall1_orn = wall_1.Orientation

local wall2_orn = wall_2.Orientation


TweenService = game:GetService('TweenService')


local wall_speed = 3


local tweenInfo = TweenInfo.new(

wall_speed, -- Time

Enum.EasingStyle.Linear, -- EasingStyle

Enum.EasingDirection.Out, -- EasingDirection

0, -- RepeatCount

true, -- Reverses

0 -- DelayTime

)



local function activate(otherPart)

local humanoid = otherPart.Parent:FindFirstChild('Humanoid')

if humanoid and not trap_activated then

trap_activated = true

wall_1.Orientation = wall2_orn

wall_2.Orientation = wall1_orn

TweenService:Create(wall_1, tweenInfo, {Position = stop_1}):Play()

TweenService:Create(wall_2, tweenInfo, {Position = stop_2}):Play()

wait(wall_speed * 2)

wall_1.Orientation = wall1_orn

wall_2.Orientation = wall2_orn

trap_activated = false

end

end


local function spiked(otherPart)

local humanoid = otherPart.Parent:FindFirstChild('Humanoid')

if humanoid then

humanoid.Health = 0

end

end


trigger.Touched:Connect(activate)

wall_1.Touched:Connect(spiked)

wall_2.Touched:Connect(spiked)