Why is this tween not accurate?

Working on a tycoon system where objects and new buttons are “tweened” from being small to being their proper size on the client for effects, like seen below:

However, when it does this to the next button(s), it does the following:

  • Makes them too big. There are two MeshParts in the button(s), and they are meant to be (4.269, 0.552, 4.489) and (5.023, 0.435, 5.282) in size. After tweening, they are (7.023, 0.608, 7.384) and (5.969, 0.772, 6.276).
  • The billboard GUI for them becomes incredibly small and unreadable.

This video shows the issues mention above:

Here is the code I use:

local replicatedStorage = game:GetService("ReplicatedStorage")
local clients = replicatedStorage.events.client

local tweenModule = require(replicatedStorage.modules.TMmoduleV2)

local info = TweenInfo.new(.25,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)

clients.tweenSize.OnClientEvent:Connect(function(obj:Model,name:string)
	if obj.PrimaryPart then
		local sizeDiff = 10
		
		print(tostring(obj))
		obj:ScaleTo((1/sizeDiff))
		task.spawn(function()
			--module.TweenModulePosition(clone,info2,pos)
			tweenModule.TweenModuleScale(obj,info,sizeDiff)
		end)
	end
end)

---module that does the tweening:
function module.TweenModuleScale(Model,Tweeninfo,Size,DeleteAfterTween)
	if typeof(Model) ~= "Instance" then error(Model.." isnt a instance") end
	if not Model:IsA("Model") then error(Model.Name.." isnt a model") end
	if not Model.PrimaryPart then Model.PrimaryPart = Model:FindFirstChildWhichIsA("BasePart") end

	task.spawn(function()
		local Primary = Model.PrimaryPart
		local AnchorState = Primary.Anchored

		local TW = TS:Create(Primary,Tweeninfo,{Size = Primary.Size * Size})

		for _,v in pairs(Model:GetDescendants()) do
			if v:IsA("BasePart") and v ~= Primary then
				local state = v.Anchored
				v.Anchored = true
				local T = TS:Create(v,Tweeninfo,{Size = v.Size * Size;Position = v.Position + (CalculatePosition(Primary,v) * (Size-1))})
				
				task.spawn(function()
					TW:GetPropertyChangedSignal("PlaybackState"):Wait()
					if v:FindFirstChildWhichIsA("SpecialMesh") then
						local mesh = v:FindFirstChildWhichIsA("SpecialMesh")
						TS:Create(mesh,Tweeninfo,{Scale = mesh.Scale * Size}):Play()
					end
					T:Play()
					v.Anchored = state
				end)
			end

			if v:IsA("Weld") or v:IsA("WeldConstraint") or v:IsA("ManualWeld") or v:IsA("Motor6D") then
				if v.Name ~= "TweenWeld" then
					v.Enabled = false
					task.spawn(function()
						TW.Completed:Wait()
						v.Enabled = true
					end)
				end
			end
		end

		TW:Play()
		TW.Completed:Wait()
		if DeleteAfterTween then
			Model:Destroy()
		end

		Primary.Anchored = AnchorState
	end)

	return
end

So, it’s the button that is acting up here? …
This is just a guess based off things I’ve noticed in the studio.
If you paste a new size in a mesh the object will lose exactly where it was placed.
So you need to copy the location, change the size then paste back in the location.

I’m amusing that is what is happening here in real time.
Making the fix to simply put the obj (button) location back to what it was.

There were no changes to the position of the button, only its size.

Re-read what I posted … I think this is something that just happens when you change size of the mesh. There must not be a recalculation on location and that becomes offset based on the size.

In the meantime, I have chosen to go the following route:

local sizeDiff = 10
		if obj:GetAttribute("button") == true then
			local clone = obj:Clone()
			for _,i in pairs(clone:GetChildren()) do
				if i:IsA("BasePart") then
					i.CanTouch = false
				end
			end
			local ogSpot = obj.Parent
			obj.Parent = nil
			clone.Parent = ogSpot
			clone:ScaleTo((1/sizeDiff))
			tweenModule.TweenModuleScale(clone,info,sizeDiff,true)
			task.wait(0.5)
			obj.Parent = ogSpot
		else
			obj:ScaleTo((1/sizeDiff))
			task.spawn(function()
				tweenModule.TweenModuleScale(obj,info,sizeDiff)
			end)
		end
1 Like