Increase parts size gradually as one value reaches another

So I have 3 values. blastSmallValue, blastMediumValue and blastLargeValue.

Im trying to have it so when the players power level reaches these values (starting with the smallest) the players blast parts radius will increase.

e.g:
blastSmallValue = 15
blastMediumValue = 50
blastLargeValue = 100

When the players power reaches 15 the blast parts size should become 12.
When the players power reaches 50 the blast parts size should become 32.
When the players power reaches 100 the blast parts size should become 64.

How do I have it so as the players power increases and reaches the next blastSize value. The blast part can also get incrementally larger and reach its predetermined sizes instead of it just instantly changing its size the moment the required power amount is met.

You can interpolate between the sizes:

local blastSmallValue = 15
local blastMediumValue = 50
local blastLargeValue = 100
local smallSize = 12
local mediumSize = 32
local largeSize = 64

local currentPowerLevel = 30 -- example value, insert the player's power here
local blastSize = 1

if currentPowerLevel <= blastSmallValue then
	-- the progress variables are from 0 to 1 and show how close your power is to each milestone
	-- for example, having a progress value of 0.5 means you're halfway between 0 power and 15 power (the small value)
	local progressToSmall = currentPowerLevel / blastSmallValue
	blastSize = progressToSmall * smallSize
elseif currentPowerLevel <= blastMediumValue then
	-- similar formula here, we just subtract values to represent the difference between the small and medium milestones
	local progressToMedium = (currentPowerLevel - blastSmallValue) / (blastMediumValue - blastSmallValue)
	blastSize = smallSize + progressToMedium * (mediumSize - smallSize)
elseif currentPowerLevel <= blastLargeValue then
	local progressToLarge = (currentPowerLevel - blastMediumValue) / (blastLargeValue - blastMediumValue)
	blastSize = mediumSize + progressToLarge * (largeSize - mediumSize)
else
	blastSize = largeSize
end

print(blastSize) -- with 30 power: ~20 blast size

Specifically I use linear interpolation. It’s kind of hard to explain but here’s a Wikipedia article if needed

1 Like

This seems to somewhat work. But after implementing this into my script it reaches the max size (64) when the players power is 12 and seems to ignore the other blast values.

remotes.powerPartEvent.Event:Connect(function(player: Player)	
	local powerPart = player.Character:FindFirstChild("PowerPart")
	if not powerPart then return end

	terrain:FillBlock(powerPart.CFrame, powerPart.Size, Enum.Material.Air)

	local currentWorld = PlayerModule.GetCurrentWorld(player)
	local currentPowerLevel = Manager.GetPower(player)
	local blastSize = 1

	local blastSmallValue = currentWorld.Values.blastSmallValue.Value --15
	local blastMediumValue = currentWorld.Values.blastMediumValue.Value --50
	local blastLargeValue = currentWorld.Values.blastLargeValue.Value --100

	if currentPowerLevel <= blastSmallValue then
		-- the progress variables are from 0 to 1 and show how close your power is to each milestone
		-- for example, having a progress value of 0.5 means you're halfway between 0 power and 15 power (the small value)
		local progressToSmall = currentPowerLevel / blastSmallValue
		blastSize = progressToSmall * smallBlastSize
	elseif currentPowerLevel <= blastMediumValue then
		-- similar formula here, we just subtract values to represent the difference between the small and medium milestones
		local progressToMedium = (currentPowerLevel - blastSmallValue) / (blastMediumValue - blastSmallValue)
		blastSize = smallBlastSize + progressToMedium * (mediumBlastSize - smallBlastSize)
	elseif currentPowerLevel <= blastLargeValue then
		local progressToLarge = (currentPowerLevel - blastMediumValue) / (blastLargeValue - blastMediumValue)
		blastSize = mediumBlastSize + progressToLarge * (largeBlastSize - mediumBlastSize)
	else
		blastSize = largeBlastSize
	end
	
	powerPart.Size += Vector3.new(blastSize, blastSize, blastSize)

	if powerPart.Size.X > Manager.MaximumPowerPartSize then
		powerPart.Size = Vector3.new(Manager.MaximumPowerPartSize, Manager.MaximumPowerPartSize, Manager.MaximumPowerPartSize)
	end
end)

Are your power milestones set up correctly? What is the default size of the powerPart and what is the value of MaximumPowerPartSize?

The default size of the powerPart is 3 and the MaximumPowerPartSize is 64

I can’t see why it wouldn’t be working, and I can’t see the rest of the stuff so you might just have to check everything is correct with print statements.


Strange

Oh I see the problem, you’re adding onto the current size of the power part every time. You just need to change the += into =.

Yep that was it! It works perfectly now.
Thanks a bunch!