function grow() x=script.Parent.Size.X y=script.Parent.Size.Y z=script.Parent.Size.Z script.Parent.Size=Vector3.new(x+1,y+1,z+1) end function shrink() x=script.Parent.Size.X y=script.Parent.Size.Y z=script.Parent.Size.Z script.Parent.Size=Vector3.new(x-1,y-1,z-1) end script.Parent.ClickDetector.Button1Down:connect(grow) script.Parent.ClickDetector.Button2Down:connect(shrink)
That is the code used in the script. The script's parent is a part, and it has a clickDetector. (Ex. -Part ClickDetector Script)
Im trying to make a part shrink and grow using mouse1button(grow) and mouse2button(shrink), but when i test it, nothing happends.
function grow() script.Parent.Size=script.Parent.Size+Vector3.new(1,1,1) end function shrink() script.Parent.Size=script.Parent.Size-Vector3.new(1,1,1) end script.Parent.ClickDetector.MouseClick:connect(grow) script.Parent.ClickDetector.MouseClick:connect(shrink) -- You'll need another way of shrinking because you cannot use right click unless you use mouse and get target and check it then
Here's how it would work with a localscript and using the players mouse:
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Part = workspace.Brick -- your part's directory function grow() Part.Size=Part.Size+Vector3.new(1,1,1) end function shrink() Part.Size=Part.Size-Vector3.new(1,1,1) end Mouse.Button1Down:connect(function() -- if the player left clicks if Mouse.Target == Part then -- checks if the mouse is over the part when clicking grow() end end) Mouse.Button2Down:connect(function() -- if player right clicks if Mouse.Target == Part then -- checks if the mouse is over the part when clicking shrink() end end)
Hope this helps
ClickDetector doesn't have Button1Down
or Button2Down
events. It only have MouseClick
, which can be activated by Left and Right mouse buttons. It can't detect only right or only left mouse clicks, so your script can't work. But you can find another ways.
Anyway, grow or shrink function still can work, if you change Button#Down
to MouseClick
.