Part becomes bigger when mouse hovering over

Hello, im trying to make a clicker game where you click a button which is a surface gui button and i wanna make the button grow from all sides when i hover with mouse over the button.

I want to resize it by a percentage, so like 10% from all sides.

I have found a tutorial on YouTube which shows how to highlight objects by hovering mouse over them and I tried making the resize script but it didn’t work.

This is my script so far:

local Mouse = game.Players.LocalPlayer:GetMouse()
local cs = game:GetService("CollectionService")

Mouse.Move:Connect(function()
   if not Mouse.Target then
	   return
   end

   if cs:HasTag(Mouse.Target,"Scale") then
	   --Resize the part from all sides by percentage
   end
end)
2 Likes

So if I’m understanding well, your problem is that you don’t know how to resize the part by a percentage?
I would do it like that personally:

part.Size.X = part.Size.X * 1.1
part.Size.Y = part.Size.Y * 1.1
part.Size.Z = part.Size.Z * 1.1

I’m new to this but hope that helps!

1 Like

You could also do something like this:

part.Size = part.Size * 1.1
1 Like

Here is a quick and dirty example to try out:

local Mouse = game.Players.LocalPlayer:GetMouse()
local cs = game:GetService("CollectionService")
local UserInputService = game:GetService("UserInputService")

local percent = 10
local targets = {}

local function resetTargets()
	for i, v in pairs(targets) do
		i.Size = v
		i.IsScaled.Value = false
	end
	targets = {}
end

Mouse.Move:Connect(function()
	if not Mouse.Target then
		resetTargets()
		return
	end
	
	local mouseTarget = Mouse.Target
	if cs:HasTag(mouseTarget,"Scale") then
		local isScaled = mouseTarget:FindFirstChild("IsScaled")
		if isScaled == nil then
			isScaled = Instance.new("BoolValue", mouseTarget)
			isScaled.Name = "IsScaled"
		end
		
		if isScaled.Value then return end
		
		targets[mouseTarget] = mouseTarget.Size
		mouseTarget.Size *= 1 + percent/100
		mouseTarget.IsScaled.Value = true
	else
		resetTargets()
	end
end)

Thanks, this is working perfectly.

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