Returning different Parts to their original size after tweening

So, I’m trying to return a part to it’s original position after tweening. I know it could be easily done by getting it’s original position first. But here’s the problem - all of the parts are different sizes, which leads to every part getting one another’s size. Is there any way I could get all of the sizes separately, then adjusting them to their proper part?

The script for more explanation:

-- Settings
local GenerationDistanceMax = 100
local GenerationDistanceMin = 70
-- Services
local TS = game:GetService("TweenService")
local SS = game:GetService("ServerStorage")
--Variables
local MapFolder = game.Workspace.Map
local SizeFound = false
local GroundPartOriginalSize = nil

local Player = game.Players.LocalPlayer
local Character = script.Parent
local Torso = Character:WaitForChild("Torso")


local GroundPartAppearTweenInfo = TweenInfo.new (
	0.4, 						 -- Length
	Enum.EasingStyle.Bounce, 	 -- Easing Style
	Enum.EasingDirection.Out,	 -- Easing Direction
	0, 						 	 -- Times Repeated
	true, 					  	 -- Reverse
	0 						 	 -- Delay
)

local GroundPartAppearTweenGoals = {Size = Vector3.new(5,5,5)}

for i, GroundPartModel in pairs (MapFolder:GetChildren()) do
	if GroundPartModel:IsA("Model") then
		for i, GroundPart in pairs (GroundPartModel:GetChildren()) do
			if GroundPart:IsA("Part") then
				GroundPartOriginalSize = GroundPart.Size
				SizeFound = true 
			end
		end
	end
end

if SizeFound == true then
	while wait() do
		for i, GroundPartModel in pairs (MapFolder:GetChildren()) do
			if GroundPartModel:IsA("Model") then
				for i, GroundPart in pairs (GroundPartModel:GetChildren()) do
					if GroundPart:IsA("Part") then
						local GroundPartAppearTween = TS:Create(GroundPart, GroundPartAppearTweenInfo, GroundPartAppearTweenGoals)
						local GroundPartDistance = Player:DistanceFromCharacter(GroundPart.Position)
						if GroundPartDistance < GenerationDistanceMax then
							if GroundPartDistance > GenerationDistanceMin then
								GroundPart.Transparency = 0
								if GroundPart.Appeared.Value == false then
									GroundPartAppearTween:Play()
									GroundPart.Appeared.Value = true
								end
							end
						else
							if GroundPart.Appeared.Value == true then
								GroundPart.Appeared.Value = false
								GroundPart.Size = Vector3.new(GroundPartOriginalSize)
							end
					
							GroundPart.Transparency = 1
						end
					end
				end
			end
		end
	end
end

You store all the parts in a table and their original sizes. When you want to tween them back to their original size, you loop through the table and tween the parts back to the original state.

Example:


local TweenService = game:GetService("TweenService")

local PartsAndSizes = {}

-- Storing parts in the table
for i, GroundPartModel in pairs (MapFolder:GetChildren()) do
	if GroundPartModel:IsA("Model") then
		for i, GroundPart in pairs (GroundPartModel:GetChildren()) do
			if GroundPart:IsA("Part") then
				table.insert(PartsAndSizes, {Part = GroundPart, Size = GroundPart.Size})
			end
		end
	end
end

for _, parttable in pairs(PartsAndSizes) do -- We loop through the table
	-- We tween the parts back to their original sizes
	TweenService:Create(parttable.Part, TweenInfo.new(
		-- tween info goes here
		), {Size = parttable.Size})
end

I don’t understand your script so well so there’s a chance I misunderstood and you have to make changes to the script I provided you.

1 Like

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