Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a Frame Shrink gradually by pressing Left Shift. Help?

The script is supposed to shrink a frame gradually for as long as I hold down Left Shift.

Even I press left Shift NOTHING happens. No output errors, just acts like it working when its not.

local uis = game:GetService("UserInputService")
local shrinking = false
local r = 1/1000 -- gui should shrink by 0.1% on wait()
local gui = script.Parent

function Shrink()
shrinking = true
while shrinking do
local s = gui.Size
gui.Size = s - UDim2.new(s.X.Scale*r,s.X.Offset*r,s.Y.Scale*r,s.Y.Offset*r)
wait()
end
end

uis.InputBegan:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and gp then
if input.KeyCode == Enum.KeyCode.LeftShift then
Shrink()
end
end
end)

uis.InputEnded:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and gp then
if input.KeyCode == Enum.KeyCode.LeftShift then
shrinking = false
end
end
end)

1 comment

0

Please address the problem/error.

1 answer

✓ Accepted answer

I think I have found the solution, not quite sure- but hope this helps!

The problem here is the boolean gameProcessed (gp) argument. When you say this-

if input.UserInputType == Enum.UserInputType.Keyboard and gp then

You're essentially saying gp has to be true, and the only time gameProcessed is true, is when the input began on top of a GuiObject.

My suggestion would be to remove it or say 'if not gp then' because you would't want the player to be pressing shift in the chat or in a textbox or something and the frame will pop up.

Final Result;

local uis = game:GetService("UserInputService")
local shrinking = false
local r = 1/1000 -- gui should shrink by 0.1% on wait()
local gui = script.Parent

function Shrink()
shrinking = true
while shrinking do
local s = gui.Size
gui.Size = s - UDim2.new(s.X.Scale*r,s.X.Offset*r,s.Y.Scale*r,s.Y.Offset*r)
wait()
end
end

uis.InputBegan:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and not gp then
if input.KeyCode == Enum.KeyCode.LeftShift then
Shrink()
end
end
end)

uis.InputEnded:connect(function(input,gp)
if input.UserInputType == Enum.UserInputType.Keyboard and not gp then
if input.KeyCode == Enum.KeyCode.LeftShift then
shrinking = false
end
end
end)

References: http://wiki.roblox.com/index.php?title=API:Class/UserInputService/InputBegan

This discussion is preserved as it was. New answers, comments, and votes are closed.