How Do I Increase Part Size Everytime Its Hit

I know how to make the function and stuff but only problem is how do I make it increase random number between 1 to 5 on the Y axis everytime its touched?

image

2 Likes

You can just use the Resize function

part.Touched:Connect(function()
    part:Resize(Enum.NormalId.Top,math.random(1,5))
end)

Does not work

image

local part = script.Parent
local db = true -- debounce

local function onTouch(hit)
	if db then

        -- make sure a player was the touch
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)

		if player then db = false
			
			local increaseAmount = math.random(1, 5)
			part.Size = part.Size + Vector3.new(0, increaseAmount, 0)
			
			task.wait(1) -- can touch, after touched stall
			db = true
		end
	end
end

part.Touched:Connect(onTouch)

Using Resize

local part = script.Parent
local debounce = false
part.Touched:Connect(function(hit)
	if not debounce then debounce = true
		if hit.Parent:FindFirstChild("trash") then return -- or trash:Destroy()
		elseif hit.Parent:FindFirstChild("Humanoid") then
			part:Resize(Enum.NormalId.Top,math.random(2,5))
		end
	end
	task.wait(1)
	debounce = false
	end	
)

Using Size

local part = script.Parent
local debounce = false
part.Touched:Connect(function(hit)
	if not debounce then debounce = true
		if hit.Parent:FindFirstChild("trash") then return -- or trash:Destroy()
		elseif hit.Parent:FindFirstChild("Humanoid") then
			part.Size = Vector3.new(part.Size.X,part.Size.Y + math.random(2,5),part.Size.Z)
		end
	end
	task.wait(1)
	debounce = false
	end
	
)
1 Like

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