Morphing System messes up Tweens

So there is this strange bug in my game where these tweened moving lollipop platforms are working perfectly fine until you morph into one of the characters. After you morph its position changes and it starts going up higher and you can make it go higher and higher every time you morph. I have no idea how to fix this does anyone know how?

Here’s a video:

Here’s the code:

-- Tween Script
local LStorage = game.Workspace.LollipopStorage

	for i, child in pairs(LStorage:GetChildren()) do
		if child.Name == "LollipopPlatform" then
		local MovingParts = child:GetChildren()
		for i, child2 in pairs(MovingParts) do
		 if child2:IsA("BasePart") then
				
				local TweenService = game.TweenService
				local Info = TweenInfo.new(
					1,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.Out,
					-1,
					true,
					0
				)


				local PropertyTable = {
					Position = child2.Position + Vector3.new(0,10,0)
				}
				local OriginalPosition = child2.Position
				local Tween = TweenService:Create(child2, Info, PropertyTable)
				Tween:Play()
		end
	end
	end
end
-- Morphing Script
local changeEvent = game.ReplicatedStorage:WaitForChild("MorphEvent")

local charsFolder = game.ReplicatedStorage:WaitForChild("Characters")

changeEvent.OnServerEvent:Connect(function(player,chosenCharacter)
	local char = player.Character
	if charsFolder:FindFirstChild(chosenCharacter) then
		local newChar = charsFolder:FindFirstChild(chosenCharacter):Clone()
		local plrChar = player.Character

		if newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.HumanoidRootPart
			newChar:SetPrimaryPartCFrame(plrChar.HumanoidRootPart.CFrame)
		elseif newChar:FindFirstChild("Torso") and not newChar:FindFirstChild("HumanoidRootPart") then
			newChar.PrimaryPart = newChar.Torso
			newChar:SetPrimaryPartCFrame(plrChar.Torso.CFrame)
		end	

		local NameTag = game.ReplicatedStorage.NameTag:Clone()
		newChar.Name = player.Name
		
		newChar.Humanoid.DisplayName = char.Humanoid.DisplayName
		player.Character = newChar
		NameTag.Parent = player.Character
		

		

		local rootPart = newChar:FindFirstChild("HumanoidRootPart") or newChar:FindFirstChild("Torso")
		local plrRoot = player.Character:FindFirstChild("HumanoidRootPart") or player.Character:FindFirstChild("Torso")

		if rootPart and plrRoot then
				rootPart.CFrame = plrRoot.CFrame
		end
		
		newChar.Parent = workspace
		NameTag.Parent = player.Character
		NameTag.CFrame = player.Character.Head.CFrame * CFrame.new(0,0.65,0)
		local Weld = Instance.new("Weld")
		Weld.Part0 = NameTag
		Weld.Part1 = player.Character.Head
		Weld.C0 = NameTag.CFrame:inverse()
		Weld.C1 = player.Character.Head.CFrame:inverse()
		Weld.Parent = NameTag
		NameTag.BillboardGui.TextLabel.Text = char.Humanoid.DisplayName
		local NameTagColor = math.random(1,7)
		if NameTagColor == 1 then
			NameTag.BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(85, 255, 0)
		elseif NameTagColor == 2 then
			NameTag.BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(255, 0, 0)
		elseif NameTagColor == 3 then
			NameTag.BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 0)
		elseif NameTagColor == 4 then
			NameTag.BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(0, 0, 255)
		elseif NameTagColor == 5 then
			NameTag.BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(170, 0, 255)
		elseif NameTagColor == 6 then
			NameTag.BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(0, 255, 255)
		elseif NameTagColor == 7 then
			NameTag.BillboardGui.TextLabel.TextColor3 = Color3.fromRGB(255, 0, 255)
		end
		
		
	else
		warn("character doesnt exist or something went wrong.")
	end
end)


please supply relevant code with your posts

Sorry, my bad I added the 2 scripts

Is the tween script in StarterGui? If so, try putting it in StarterPlayerScripts, as it would reset on spawn if it was in StarterGui.

2 Likes

Not really sure how this happened, but instead of tweening a platform to move up and down, I recommend using math functions like math.sin or math.cos.
These functions take one value, as if it’s the x position on a graph, and returns a number between one and negative one depending on where on the graph it is.
Anyways, enough explanation. Here’s an example

local value = 0 -- the value to be inserted into the function
local max = 2 --the max high / low of the platform's position
local pos = -- whatever position the platform's at
local platform = --the platform
while wait() do -- forever do
value += 1 -- change this to how or fast you want the platform to move, wouldn't recommend letting the value increase for eternity, though
platform.Position = pos + Vector3.new(0,math.sin(value)*max)
end

In this example, the platform, like a wave, will smoothly bob up and down.

you can just change tweeninfo to run the animation back and forth

1 Like

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