Script
local Sequences = {}
local function RegisterSequence(SequenceObj)
if SequenceObj.Registered == nil then return end
SequenceObj.Registered = nil
for PartIndex, Part in pairs(SequenceObj.Parts) do
Part.Touched:Connect(function(hit)
if PartIndex <= SequenceObj.Index then return end
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not Player then return end
if SequenceObj.Index == -1 then return end
if SequenceObj.Index+1 == PartIndex then
if SequenceObj.Stepped(SequenceObj, Player, Part) then
if PartIndex == #SequenceObj.Parts then
SequenceObj.Complete(SequenceObj, Player, Part)
if not SequenceObj.Index == -1 then SequenceObj.Index = 0 end
else
SequenceObj.Index = PartIndex
end
end
else
SequenceObj.Fail(SequenceObj, Player, Part)
if not SequenceObj.Index == -1 then SequenceObj.Index = 0 end
end
end)
end
end
local function AddSequence(Name, Parts, Stepped, Fail, Complete)
local nSequenceObj = {}
nSequenceObj["Name"] = Name
nSequenceObj["Parts"] = Parts
nSequenceObj["Stepped"] = Stepped
nSequenceObj["Fail"] = Fail
nSequenceObj["Complete"] = Complete
nSequenceObj["Index"] = 0
nSequenceObj["Registered"] = false
table.insert(Sequences, nSequenceObj)
RegisterSequence(nSequenceObj)
end
AddSequence("Rising",
{
workspace.p1,
workspace.p2,
workspace.p3,
workspace.p4
},
function(this, Player, TouchPart) -- Stepped
print("("..this.Name..") Sequence stepped: "..(this.Index+1).."/"..#this.Parts)
TouchPart.Color = Color3.fromRGB(56, 62, 54) -- Stepped Color
return true
end,
function(this, Player, TouchPart) -- Failed
print("("..this.Name..") Sequence failed at: "..(this.Index+1).."/"..#this.Parts)
this.Index = -1 -- Disable sequence
coroutine.wrap(function()
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(154, 0, 2) -- Flash Red
end
wait(.5)
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(163, 162, 165) -- Regular Color
end
this.Index = 0 -- Enable sequence
end)()
end,
function(this, Player, TouchPart) -- Completed
this.Index = -1 -- Disable sequence
print("("..this.Name..") "..Player.Name.." has completed the sequence")
coroutine.wrap(function()
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(47, 154, 8) -- Flash Green
end
wait(.5)
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(56, 62, 54) -- Disabled Color
end
wait(2)
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(163, 162, 165) -- Regular Color
end
this.Index = 0 -- Enable sequence
end)()
end
)
AddSequence("Falling",
{
workspace.p21,
workspace.p22,
workspace.p23,
workspace.p24
},
function(this, Player, TouchPart) -- Stepped
print("("..this.Name..") Sequence stepped: "..(this.Index+1).."/"..#this.Parts)
TouchPart.Color = Color3.fromRGB(56, 62, 54) -- Stepped Color
return true
end,
function(this, Player, TouchPart) -- Failed
print("("..this.Name..") Sequence failed at: "..(this.Index+1).."/"..#this.Parts)
this.Index = -1 -- Disable sequence
coroutine.wrap(function()
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(154, 0, 2) -- Flash Red
end
wait(.5)
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(163, 162, 165) -- Regular Color
end
this.Index = 0 -- Enable sequence
end)()
end,
function(this, Player, TouchPart) -- Completed
this.Index = -1 -- Disable sequence
print("("..this.Name..") "..Player.Name.." has completed the sequence")
coroutine.wrap(function()
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(47, 154, 8) -- Flash Green
end
wait(.5)
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(56, 62, 54) -- Disabled Color
end
wait(2)
for _, p in pairs(this.Parts) do
p.Color = Color3.fromRGB(163, 162, 165) -- Regular Color
end
this.Index = 0 -- Enable sequence
end)()
end
)