Trying to tween model position + secondary model orientation when proximity prompt is triggered

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.

1 Like

Have you weld your parts to the PrimaryPart?

1 Like

I tried that, but it didn’t work. Nothing moves still.

I ended up finding a solution on my own, although it requires all parts to be welded together, and all parts except the PrimaryPart or the part that you’re directly moving to be unanchored.

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.Exponential, Enum.EasingDirection.Out, 0, false)
			local endPos = CFrame.new(-36.75, 15, 9.5)
			local info2 = TweenInfo.new(0.3, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false)
			local endOrientation = CFrame.Angles(math.rad(120), 0, 0)

			if WindowCover.PrimaryPart and Lever.PrimaryPart then
				tweenService:Create(WindowCover.PrimaryPart, info, {CFrame = endPos}):Play()
				local currentCFrame = Lever.PrimaryPart.CFrame
				tweenService:Create(Lever.PrimaryPart, info2, {CFrame = currentCFrame * endOrientation}):Play()
				Audio:Play()
			else
				warn("PrimaryPart is not set for WindowCover or Lever")
			end

			task.wait(0.8)
			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.Exponential, Enum.EasingDirection.Out, 0, false)
			local endPos = CFrame.new(-36.75, 8, 9.5)
			local info2 = TweenInfo.new(0.3, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false)
			local endOrientation = CFrame.Angles(math.rad(-120), 0, 0)

			if WindowCover.PrimaryPart and Lever.PrimaryPart then
				tweenService:Create(WindowCover.PrimaryPart, info, {CFrame = endPos}):Play()
				local currentCFrame = Lever.PrimaryPart.CFrame
				tweenService:Create(Lever.PrimaryPart, info2, {CFrame = currentCFrame * endOrientation}):Play()
				Audio:Play()
			else
				warn("PrimaryPart is not set for WindowCover or Lever")
			end

			task.wait(0.8)
			Prompt.Enabled = true
			Value.Value = true
			db = false
		end
	end
end

Prompt.Triggered:Connect(Toggle)


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.