Hello, recently i got a problem with mobile game controls. I made a Mouse.KeyDown event, but if i jump or press gui button, it still works, how would i make that if i press any gui button the function will ignore?
What do you mean by “if i jump or press gui button, it still works.”
You want player not jump when the UI button is clicked?
No, I want to make it so that if the player on mobile device presses jump button or any GUI button, Mouse.KeyDown event will ignore that.
Well Mouse.KeyDown
is so old.
You should use UserInputService
Example:
local userinput = game:GetService("UserInputService")
userinput.InputBegan:Connect(function(obj)
if obj.UserInputType == Enum.UserInputType.Keyboard then
print("Key is pressed on a keyboard")
end
end)
I tried UserInputService too, and i found in there TouchTap event, but it is the same, it won’t ignore GUI buttons, that’s the problem.
Well I still dont understand this line.
What are you trying to make exactly? You can check if player is jumping or not by using Humanoid:GetState() == Enum.HumanoidStateType.Jummping
then it will return false or true depending if humanoid is jumping or not.
My bad, i said Mouse.KeyDown but i meant Mouse.Button1Down, i want Mouse.Button1Down event to not work when any GUI button is being pressed
Ohh, I still don’t understand what are you trying to make.
Can you explain it to me in detail well I got it you are trying to pause button1down event.
But why? like if player is click (A) button then they cant click (B) button?
So, basically i want player, for example, attack by tapping screen on mobile, and there is a GUI button to switch weapon, but whenever he presses this GUI button he switches weapon AND attacks, but i want him to just switch weapon, without attacking. I want Mouse.Button1Down to not work when he is switching weapon.
I see, you can add a bool value in player.
and for your Mouse.Button1Down
local player = game.Players.LocalPlayer
Mouse.Button1Down:Connect(function()
local db = player.Debounce
if db.Value == true then
return
end
-- your code stuff here
end)
Now your gui button
local player = game.Players.LocalPlayer
button.MouseButton1Down:Connect(function()
local db = player.Debounce
db.Value = true
-- gui button stuff here
end)
button.MouseButton1Up:Connect(function()
local db = player.Debounce
db.Value = false
end)
Oh, i got it now, thanks a lot!
you can make a blacklist table with blacklisted ui’s that you dont want triggering the attacks and you can use this and pass in the mouse / tapped positions and check if any of the ui’s are blacklisted if so do not do the attack so something like:
local pg = game.Players.LocalPlayer.PlayerGui
local blackList = {pg.Inventory.MainFrame} -- or anything this allows any ui object such as frames
Mouse.Button1Down:Connect(function()
local hovering = pg:GetGuiObjectsAtPosition(Mouse.X, Mouse.Y);
for _, val in pairs(blackList) do
for _, hover in pairs(hovering) do
if hover:IsDescendantOf(val) then
return;
end
end
end
end)
this should alloww you to blacklist frames very quickly
Thanks, this is a good one too, but i already found out that UserInputService.TouchTapInWorld already had a bool, which is false when it is not pressing any gui and true if pressing a gui