Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

can someone please help me with tweening a model pretty please?

https://gyazo.com/8785e05347b36fc1d0fc03e25ae4eb80 im trying to tween a model but for some reason it glitches when closing

local openDoor = script.Parent.Parent.Parent.DoorOpen
local closeDoor = script.Parent.Parent.Parent.DoorClose
local move = script.Parent.Parent.Move

local open = script.Parent.Parent.Open.Value

local clickdetector = script.Parent.ClickDetector

local tweenservice = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(
            0.5,
            Enum.EasingStyle.Quad,
            Enum.EasingDirection.InOut,
            0,
            false,
            0
)

local function tweenModel(model, CF)
    local CFrameValue = Instance.new("CFrameValue")
    CFrameValue.Value = model:GetPrimaryPartCFrame()

    CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
        model:SetPrimaryPartCFrame(CFrameValue.Value)
    end)
    
    local tween = tweenservice:Create(CFrameValue, tweeninfo, {Value = CF})
    tween:Play()
    
    tween.Completed:Connect(function()
        CFrameValue:Destroy()
    end)
end

clickdetector.MouseClick:Connect(function(plr)
    
    if not open then
        
        open = true
        
        tweenModel(script.Parent.Parent,openDoor:GetPrimaryPartCFrame())
        
    end
    
    if open then
        
        open = false
        
        tweenModel(script.Parent.Parent,closeDoor:GetPrimaryPartCFrame())
        
    end
    
end)

1 answer

✓ Accepted answer

The problem is that your using 2 if statements. The alternative is to combine them.

clickdetector.MouseClick:Connect(function(plr)
 
    if not open then
 
        open = true
 
        tweenModel(script.Parent.Parent,openDoor:GetPrimaryPartCFrame())
	
	elseif open then
	
		open = false
		tweenModel(script.Parent.Parent,closeDoor:GetPrimaryPartCFrame())
 
    end
 
end)

The reason it's glitchy was because after the first if-statement, the second if-statement ran.

1 comment

0

thx

This discussion is preserved as it was. New answers, comments, and votes are closed.