Faces are not Changing in Sync with Tweens

I’m trying to make a block that makes an angry face, smashes down, then becomes more calm and rises up, repeating the process, similar to a Thwomp in Super Mario.

However, when I attempt to change the faces at the right time, this is usually the result:
block

And that’s what happens when I run the game. When I test it as a client, the faces may have a different result, or the faces change with perfect timing, but the opposite faces appear instead, and I cannot find the problem in the script.

This is the script.
--Variables
local TweenService = game:GetService("TweenService")
local smashPart = script.Parent
local pos = smashPart.Position
local newPos = pos + Vector3.new(0, -17, 0)
local angry1 = smashPart.Angry1
local angry2 = smashPart.Angry2
local angry3 = smashPart.Angry3
local angry4 = smashPart.Angry4
local idle1 = smashPart.Idle1
local idle2 = smashPart.Idle2
local idle3 = smashPart.Idle3
local idle4 = smashPart.Idle4
local tweenInfo = TweenInfo.new(
    1.25, -- Time
    Enum.EasingStyle.Linear, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
	0, -- RepeatCount (when less than zero the tween will loop indefinitely)
    false, -- Reverses (tween will reverse once reaching it's goal)
    3 -- DelayTime
)

local tweenInfo2 = TweenInfo.new(
	1.25, -- Time
    Enum.EasingStyle.Linear, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    0, -- RepeatCount (when less than zero the tween will loop indefinitely)
	false, -- Reverses (tween will reverse once reaching it's goal)
    2 -- DelayTime
)

local tweenFall = TweenService:Create(smashPart, tweenInfo, {Position = newPos})
local tweenUp = TweenService:Create(smashPart, tweenInfo2, {Position = pos})

--Tweens
tweenFall:Play() --Starts the fall tween

tweenFall.Completed:Connect(function()
    tweenUp:Play() --Play the up tween when the fall tween is finished
end)

tweenUp.Completed:Connect(function()
	tweenFall:Play() --Play the fall tween when the up tween is finished
end)

--Looping the faces
while true do
    --The fall tween will play in 3 seconds
	angry1.Transparency = 1
	angry2.Transparency = 1
	angry3.Transparency = 1
    angry4.Transparency = 1 --Making angry faces disappear
    idle1.Transparency = 0
    idle2.Transparency = 0
    idle3.Transparency = 0
    idle4.Transparency = 0 --Making the idle faces appear
	print("test")
    wait(3)
    --The fall tween will play
    angry1.Transparency = 0
    angry2.Transparency = 0
    angry3.Transparency = 0
    angry4.Transparency = 0 --Making angry faces appear
    idle1.Transparency = 1
    idle2.Transparency = 1
    idle3.Transparency = 1
    idle4.Transparency = 1 --Making the idle faces disappear
	print("test")
    wait(1.25)
    --The fall tween ends
    wait(2)
	--The up tween will begin
    angry1.Transparency = 1
    angry2.Transparency = 1
    angry3.Transparency = 1
    angry4.Transparency = 1 --Making angry faces disappear
    idle1.Transparency = 0
	idle2.Transparency = 0
	idle3.Transparency = 0
	idle4.Transparency = 0 --Making the idle faces appear
	print("test")
	wait(1.25)
    --The up tween ends
end
  1. What do you want to achieve? I want to make a part crash down and to change it’s faces when it does.

  2. What is the issue? The faces are not changing in sync with the tweens, and I cannot figure out why.

  3. What solutions have you tried so far? I searched for similar topics, but I couldn’t find anything relevant to my issue.

I have includes comments with the wait()'s, and thought it through many times, but I still couldn’t figure out why the faces weren’t changing with good timing.

Edit: I’m not tweening the faces, I’m tweening the position of the part.

1 Like

From my understanding, the Thwomp’s faces change before they begin to move, so instead of tweening them, why not directly change the face before the tween begins?

Also why are there so many faces in your script when visually there are only two from the clip that you gave us?

1 Like

If you mean that I’m trying to tween the faces, you’re wrong. I tweened the position of the part, not the faces. Sorry for the misunderstanding.

Also, there are 4 faces for every side of the part (except top and bottom).

1 Like

I see. My mistake for misinterpreting.

From what I see, you have the faces change completely independent from the tweens themselves. Instead of having a while loop, why not change the faces transparency after each tween is initially played like this:

tweenFall.Completed:Connect(function()
    tweenUp:Play() --Play the up tween when the fall tween is finished
    angry1.Transparency = 1
    angry2.Transparency = 1
    angry3.Transparency = 1
    angry4.Transparency = 1 --Making angry faces disappear

    idle1.Transparency = 0
    idle2.Transparency = 0
    idle3.Transparency = 0
    idle4.Transparency = 0
end)

tweenUp.Completed:Connect(function()
    tweenFall:Play() --Play the fall tween when the up tween is finished
    angry1.Transparency = 0
    angry2.Transparency = 0
    angry3.Transparency = 0
    angry4.Transparency = 0 --Making angry faces appear

    idle1.Transparency = 1
    idle2.Transparency = 1
    idle3.Transparency = 1
    idle4.Transparency = 1
end)

This way, your faces will always change in sync.

1 Like

I feel like an idiot for not thinking of that. Thank you.

No problem!

We’re all here to learn!

1 Like