I have a lever that’s supposed to toggle a metal window covering up and down, along with flipping the lever either up or down. It’s also supposed to play a sound effect when toggled.
Currently I’m using this script:
local tweenService = game:GetService("TweenService")
local Prompt = script.Parent
local Lever = script.Parent.Parent.Parent.Main.Model
local WindowCover = game.Workspace.LeftSide.WindowCover
local Value = script.Parent.Parent.Parent.Value
local Audio = script.Parent.Parent.Parent.Parent.Window.WindowToggle
local db = false
local function Toggle()
if Value.Value == true then
if db == false then
db = true
Prompt.Enabled = false
local info = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local endPos = CFrame.new(-36.275, 15, 9.5)
local info2 = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local endPos2 = CFrame.Angles(60, -90, 0)
if WindowCover.PrimaryPart and Lever.PrimaryPart then
tweenService:Create(WindowCover.PrimaryPart, info, {CFrame = endPos}):Play()
tweenService:Create(Lever.PrimaryPart, info2, {CFrame = endPos2}):Play()
Audio:Play()
else
warn("PrimaryPart is not set for WindowCover or Lever")
end
task.wait(0.5)
Prompt.Enabled = true
Value.Value = false
db = false
end
elseif Value.Value == false then
if db == false then
db = true
Prompt.Enabled = false
local info = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local endPos = CFrame.new(-36.275, 8, 9.5)
local info2 = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false)
local endPos2 = CFrame.Angles(-60, -90, 0)
if WindowCover.PrimaryPart and Lever.PrimaryPart then
tweenService:Create(WindowCover.PrimaryPart, info, {CFrame = endPos}):Play()
tweenService:Create(Lever.PrimaryPart, info2, {CFrame = endPos2}):Play()
Audio:Play()
else
warn("PrimaryPart is not set for WindowCover or Lever")
end
task.wait(0.5)
Prompt.Enabled = true
Value.Value = true
db = false
end
end
end
Prompt.Triggered:Connect(Toggle)
When the proximity prompt is triggered, it turns off for 0.5 seconds, then on again as intended. It also plays the audio. However, the models don’t move or rotate at all.