Tween doesnt play

So I am making a script in serverscriptservice where its supposed to weld a part to the player then make the mesh inside the part tween to a specific size. But the tween doesnt play or happen. This is the script inside ServerScriptService:

local function cover(part,type,where)
	local weld = Instance.new("Weld",part)
	local Goo = game.Lighting.Goo:Clone()
	Goo.Parent = part.Parent
	Goo.Size = part.Size
	Goo.Color = TransformValue.Value
	weld.Part0 = part
	weld.Part1 = Goo

	if where == "top" then
	Goo.Mesh.Offset = Vector3.new(0,1,0)
	end
	if type == "head" then
	Goo.Mesh.MeshType = Enum.MeshType.Head
	Goo.Mesh.Scale = Vector3.new(1.25,0,1.25)
	game:GetService("TweenService"):Create(Goo.Mesh, TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Scale = Vector3.new(1.26,1.26,1.26),Offset = Vector3.new(0,0,0)}):Play()
	local e = game.Lighting.Faces:GetChildren()
	local face = e[math.random(1,#e)]:Clone()
	face.Parent = Goo
	else

	Goo.Mesh.MeshType = Enum.MeshType.FileMesh
	Goo.Mesh.MeshId = "rbxassetid://430080282"
	if type == "torso" then
	Goo.Mesh.Scale = Vector3.new(2.05,0,1.05)
	Goo.Noise.PlaybackSpeed = 0.85
	game:GetService("TweenService"):Create(Goo.Mesh, TweenInfo.new(0.75,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Scale = Vector3.new(2.05,1.05,1.05),Offset = Vector3.new(0,0,0)}):Play()
	
	game:GetService("TweenService"):Create(Goo.Mesh, TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Scale = Vector3.new(1.05,1.05,1.05),Offset = Vector3.new(0,0,0)}):Play()
	end
	end
	Goo.Noise:Play()
	end
game:GetService("TweenService"):Create(Goo.Mesh, TweenInfo.new(0.75,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Scale = Vector3.new(2.05,1.05,1.05),Offset = Vector3.new(0,0,0)}):Play()

game:GetService("TweenService"):Create(Goo.Mesh, TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Scale = Vector3.new(1.05,1.05,1.05),Offset = Vector3.new(0,0,0)}):Play()

You’re creating two tweens that are both changing the same properties of an object. When this is done, the first tween will be cancelled and only the newest one will be played. You need to wait until the first tween has finished playing before you play the second one.

1 Like

How can I put it in the code so it works? after that function is made this is the code that I run:

cover(Character["Left Arm"],"limb","bottom")
cover(Character["Right Arm"],"limb","bottom")
cover(Character["Left Leg"],"limb","bottom")
cover(Character["Right Leg"],"limb","bottom")

If you want to keep the two tweens on the same properties I suggest using the Completed event to check when the tweens have stopped, that way you’ll be able to proceed to the next one. I do recommend checking the TweenService, and Tween API-References

Here’s a link for that: Tween | Roblox Creator Documentation

If you need all of these to run in parallel with one another, you can use coroutine or spawn. Simplest way I can think of would be to do something like

spawn(function()
     Goo.Noise:Play()

     local tween = game:GetService("TweenService"):Create(Goo.Mesh, TweenInfo.new(0.75,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Scale = Vector3.new(2.05,1.05,1.05),Offset = Vector3.new(0,0,0)})
     tween:Play()
     tween.Completed:Wait()

     tween = game:GetService("TweenService"):Create(Goo.Mesh, TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut), {Scale = Vector3.new(1.05,1.05,1.05),Offset = Vector3.new(0,0,0)})
     tween:Play()
end)

Just replace the end of your function where you create all the tweens and play the noise with this. Should do the trick, though coroutine would be a better option as there is a slight delay when using spawn.

However, if you want all of these function calls to happen one after another, not in parallel, then you should just use Tween.Completed:Wait() in a similar fashion as I showed above.

I dont understand Coroutines and spawn I am an intermediate scripter. Can you explain more? How would I do it for each 2 parts at the same time? so the arms first then legs which is in the code?

Coroutines and Spawn are what you use in order to have code run in parallel with one another. Take these function calls, for example.

cover(Character["Left Arm"],"limb","bottom")
cover(Character["Right Arm"],"limb","bottom")
cover(Character["Left Leg"],"limb","bottom")
cover(Character["Right Leg"],"limb","bottom")

If you did not use Coroutine or Spawn in those functions, then each one would yield until the tweens created in them finished completely. Only then would it return and recall the function with slightly different parameters.

Take this set of code, for example.

function test(x)
	spawn(function()
		print(x)
	
		wait(1)
		
		print(x + 1)
	end)
end

function test2(x)
	print(x)
	
	wait(1)
	
	print(x + 1)
end

test(5) test(6) test(7)

wait(2)
print("")

test2(5) test2(6) test2(7)

Because the first function uses Spawn, the output will look like 5, 6, 7, 6, 7, 8. Compare this to the second function, which does not use Spawn and produces an output like 5, 6, 6, 7, 7, 8

1 Like