Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't my Grow/Shrink Script work?

Asked by 9 years ago

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.

2 answers

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago
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

0
Please explain your answers. Discern 1007 — 9y
0
Sorry I thought it was pretty obvious. Ryzox 220 — 9y
Ad
Log in to vote
0
Answered by
Mokiros 135
9 years ago

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.

0
So how would i change it to a keyword, such as "Q" or/and "E"? ImEvangelical 0 — 9y

Answer this question