This script is located in StarterPlayerScripts
, and utilizes the ZonePlus module by @ForeverHD. Whenever a lift is used, it will make the other lifts move in the same direction. My end goal was to make one function that will work for the lift being used and the other lifts that are moving unoccupied.
local TweenService = game:GetService('TweenService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Zone = require(ReplicatedStorage:WaitForChild('Zone'))
local Lifts = workspace:WaitForChild('Lifts')
local Colors = {
Default = ColorSequence.new(Color3.fromRGB(255, 255, 255)),
Occupied = ColorSequence.new(Color3.fromRGB(0, 0, 0))
}
local function SetBeamColors(Platform, NewColor)
for _, Beam in Platform:GetChildren() do
if Beam:IsA('Beam') then
Beam.Color = NewColor
end
end
end
local function MoveLift(Lift, Callback)
local Platform = Lift.Platform
local NewStatus = Lift:GetAttribute('Status') == 'Down' and 'Up' or 'Down'
local Tween = TweenService:Create(Platform, TweenInfo.new(2), {
Position = NewStatus == 'Down' and Lift:GetAttribute('OriginalPos') or Lift:GetAttribute('LiftedPos')
})
Tween:Play()
Tween.Completed:Once(function()
Lift:SetAttribute('Status', NewStatus)
Callback()
end)
SetBeamColors(Platform, Colors.Occupied)
end
local function InitLift(Lift)
local Platform = Lift:WaitForChild('Platform')
local LiftZone = Zone.new(Lift:WaitForChild('Container'))
LiftZone.localPlayerEntered:Connect(function()
local Character = script.Parent.Parent.Character
local Humanoid = Character.Humanoid
Humanoid.WalkSpeed = 0
Humanoid.JumpHeight = 0
while Humanoid.MoveDirection.Magnitude > 0 do
Humanoid:GetPropertyChangedSignal('MoveDirection'):Wait()
end
Character:PivotTo(Platform.CFrame + Vector3.new(0, 2.5))
task.delay(0.5, function()
MoveLift(Lift, function()
Humanoid.WalkSpeed = 16
Humanoid.JumpHeight = 7.2
end)
for _, Child in Lifts:GetChildren() do
if Child ~= Lift then
MoveLift(Child, function()
SetBeamColors(Child.Platform, Colors.Default)
end)
end
end
end)
SetBeamColors(Platform, Colors.Occupied)
end)
LiftZone.localPlayerExited:Connect(function()
SetBeamColors(Platform, Colors.Default)
end)
local OriginalPos = Platform.Position
Lift:SetAttribute('OriginalPos', OriginalPos)
Lift:SetAttribute('LiftedPos', OriginalPos + Vector3.new(0, 23.8))
end
for _, Lift in Lifts:GetChildren() do
task.defer(InitLift, Lift)
end