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

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

Asked by 7 years ago
Edited 7 years ago

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)
0
Please address the problem/error. legosweat 334 — 7y

1 answer

Log in to vote
1
Answered by
legosweat 334 Moderation Voter
7 years ago
Edited 7 years ago

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

Ad

Answer this question