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

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

Asked by 7 years ago
Edited 7 years ago

-- 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)
0
What does it do when you hold down LeftShift? antonio6643 426 — 7y
0
Did you check too see if there were any errors in the Output? If so, could you please tell us what it said? TheeDeathCaster 2368 — 7y
0
Try making a GUI and put the script in the GUI or in Serverscriptservice thecoolx123 -5 — 7y
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. JoeRaptor 72 — 7y
View all comments (4 more)
0
if no one help me, then how do I move forward? JoeRaptor 72 — 7y
0
For one, you didn't set line 4, and line 3 will be 0.001: not 0.1. TheeDeathCaster 2368 — 7y
0
0.1% = 0.001. Try to google "0.1% to decimals" for proof starlebVerse 685 — 7y
0
Even if I increase it still doesn't work though. i did like 900/1000 nothing happened JoeRaptor 72 — 7y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

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
0
I do this and Roblox actually crashes. JoeRaptor 72 — 7y
0
@cabbler JoeRaptor 72 — 7y
0
Irrelevant cabbler 1942 — 7y
Ad

Answer this question