Hello! could someone help me with my code, please?
what is wrong?
I am practicing with the page code
Hello! could someone help me with my code, please?
what is wrong?
I am practicing with the page code
Its because gameprocessed didnât return true so it went to the else statement and printed that.
How could i fix that?
gameProcessed
means there was user input while you were focused inside of a text box or clicked on a gui element
Youâve got to make gameprocessedevent return true somehow.
Oh something like this?
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.A then
local keyPressed = input.KeyCode
gameProcessed = true
print("A key is being pushed down! Key:",input.KeyCode)
if gameProcessed then
print("\tThe game engine internally observed this input!")
else
print("\tThe game engine did not internally observe this input!")
end
end
end)
If you donât need to check for the gameProcessed
event then donât include it in the script. It is simply there to tell you if the user input was on a gui element.
just put a ânotâ so it will âenter your if statementâ
No just keep the same script as before but do what hell_ish said.
Another question⌠what is bad in my code? How could i use mouse buttons?
elseif input.KeyCode == Enum.UserInputType.MouseButton2 then
local keyPressed = input.KeyCode
-- Play animation track
Animator:LoadAnimation(fastPunch):Play()
print("Q key is being pushed down! Key:",input.KeyCode)
if not gameProcessed then
print("\tThe game engine internally observed this input!")
else
print("\tThe game engine did not internally observe this input!")
end
if input.UserInputType == Enum.UserInputType.MouseButton1 then -- left mouse button
-- code
end
if input.UserInputType == Enum.UserInputType.MouseButton2 then -- middle mouse button
-- code
end
if input.UserInputType == Enum.UserInputType.MouseButton3 then -- right mouse button
-- code
end
What are you trying to achieve exactly?
I am learning to program with roblox and I have this as part of my ways of learning
Okay, gameProcessed
exists to you can check if the player was typing inside a TextBox
, for example you try to check for the key Q
being held, the function activates but the player is actually chatting, if Q
is supposed to attack for example, the player will attack while he meant to type in the chat, if you use if not gameProcessed then
when the player uses the Q
key, it will only attack if the player wasnât typing inside a TextBox
Got it?
The second parameter to InputBegan
returns a boolean indicating whether a player interacted with a GUI (graphical user interface), typing in a TextBox such as the in-game chat, or the settings menu.
If the player was doing such any of the above previously mentioned, the return value would be true
- however, if none of those were done, the return value would be false
.
To break it down into code,
UserInputService.InputBegan:Connect(function(KeyInfo, GameProcess)
if GameProcess then -- This includes GUI interactions, typing in a TextBox, or being in the settings menu.
print("Was a game process!")
else -- If the player didn't do any of the previously mentioned.
print("Was not a game process!")
end
end)
It will still return the inputted character, but the booleanâs there if you want to prevent specific code from executing from, say, a player typing in the chat and your custom inventory opening up because of it.
UserInputService.InputBegan:Connect(function(KeyInfo, GameProcess)
if GameProcess then
print("Was a game process!")
else
if KeyInfo.KeyCode == Enum.KeyCode.I then
InventoryGui.Enabled = not InventoryGui.Enabled
end
end
end)
I hope this helped.