Hello! I have decided to add an elevator to my game! I want to add a feature where after you prompt the open and walk in, it will close, and teleport you after a wait time. The problem is, I do not know how to go about some of the features. I only have the prompt done. (After using a model, but I still need the close-on walk in, and teleport after wait time.)
Here’s the code!
– Services –
local RunService = game:GetService(“RunService”)
local TweenService = game:GetService(“TweenService”)
– Instances –
local ProximityPrompts = script[“Proximity Prompts”]
local Settings = script.Settings
local Block = script.Parent
– Variables –
local proximityPrompts = {}
local connections = {}
local tween
local isOpen = false
local shrinkSpeed = Settings[“Shrink speed”].Value
local openGoal
local closedGoal
– Functions –
local function setUp()
closedGoal = {Size = Block.Size, Position = Block.Position}
local smallSize = Vector3.new((Block.Size.X), (0.05), (Block.Size.Z))
--local smallPosition = Vector3.new((Block.Position.X), (Block.Position.Y - Block.CFrame.UpVector * Block.Size.Y * -0.5), (Block.Position.Z))
local smallPosition = Block.Position + Block.CFrame.UpVector * Block.Size.Y * 0.5
openGoal = {Size = smallSize, Position = smallPosition}
end
local function getProximityPrompts()
for index, child in pairs(ProximityPrompts:GetChildren()) do
if child:IsA(“ObjectValue”) then
local prompt = child.Value
if prompt:IsA(“ProximityPrompt”) then
table.insert(proximityPrompts, prompt)
end
end
end
end
local function tweenTo(goal)
if tween then
tween:Destroy()
end
local duration = math.abs((Block.Size.Y - goal.Size.Y) / shrinkSpeed)
local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
tween = TweenService:Create(Block, tweenInfo, goal)
tween:Play()
if isOpen then
isOpen = false
else
isOpen = true
end
end
local function onTriggered(player)
if isOpen then
tweenTo(closedGoal)
else
tweenTo(openGoal)
end
end
– Code –
setUp()
getProximityPrompts()
for index, prompt in ipairs(proximityPrompts) do
local connection = prompt.Triggered:Connect(onTriggered)
table.insert(connections, connection)
end
Please help! (I would appreciate a modified version of the script if possible, because I am not the best at Lua yet!)