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)