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

Trying to make hunger bar decrease when I press Left shift. (?)

-- Made script that shrinks a frame as I hold down button.

Why it not work?

local uis = game:GetService("UserInputService")
local shrinking = false
local r = 1/1000 -- gui should shrink by 0.1% on wait() but doesn't 0.001 as a percentage is 0.1%
local gui =  script.Parent -- change this at your discretion

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)
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)

8 comments

0

What does it do when you hold down LeftShift?

0

Did you check too see if there were any errors in the Output? If so, could you please tell us what it said?

0

Try making a GUI and put the script in the GUI or in Serverscriptservice

0

I did and No output errors. The frame supposed to decreases in size for as long as I hold down left shift. Script not work.

0

if no one help me, then how do I move forward?

0

For one, you didn't set line 4, and line 3 will be 0.001: not 0.1.

0

0.1% = 0.001. Try to google "0.1% to decimals" for proof

0

Even if I increase it still doesn't work though. i did like 900/1000 nothing happened

1 answer

Here is the problem:

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

"gp" is a bool that stands for Game Processed Event, which is only true when the input happened upon an interface. You most likely DON'T want this, because then your function only works when you type into chat. Therefore you should say "and (not gp)" at the end of both functions.

Fixed:

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

3 comments

0

I do this and Roblox actually crashes.

0

@cabbler

0

Irrelevant

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