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