Desk tweenservice help

image

local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")

local TweenInfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false
)

local function PlayOpenAnimation(primaryPart)
	local goal = {CFrame = primaryPart.CFrame * CFrame.new(3, 0, 0)}
	local tween = TweenService:Create(primaryPart, TweenInfo, goal)
	tween:Play()
end

local function PlayCloseAnimation(primaryPart)
	local goal = {CFrame = primaryPart.CFrame * CFrame.new(-3, 0, 0)}
	local tween = TweenService:Create(primaryPart, TweenInfo, goal)
	tween:Play()
end

for _, v in pairs(CollectionService:GetTagged("Desk")) do
	local open = v:WaitForChild("Open")
	if open then
		local Front = open:WaitForChild("Front")
		local ProximityPrompt = Front:WaitForChild("Fro"):WaitForChild("Prompt")

		if ProximityPrompt then
			local primaryPart = Front.PrimaryPart
			local isOpen = false

			ProximityPrompt.Triggered:Connect(function()
				if isOpen then
					PlayCloseAnimation(primaryPart)
					isOpen = false
					print("close desk")
				else
					PlayOpenAnimation(primaryPart)
					isOpen = true
					print("open desk")
				end
			end)
		else
			warn("[ERROR] Desk")
		end
	end
end

it only move the front
image

Tweens won’t moved welded parts with it unless they are unanchored, I don’t have enough context to whip up a better solution than that

1 Like

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