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

How can i make it so that when one button is being pressed no other buttons can be pressed and work?

Asked by 6 years ago

Problem

I have a script that when pressed it will create a part and put it in the workspace 0,0,-5 away from the player. When let go it will destroy that Part. All that works fine but the player can summon two parts and the same time. So when one button is already being held another button can also be held and work. I want to prevent this. I've tried Multiple Solution like give both UIS the same debounce var. Although this make it so that you have to wait until the other debounce is finished until the other button can work. Which i don't want. I want it so that when a player holds a button any other buttons cannot work. When he lets go the button the he was holding onto it will have a debounce. And all other button do not have the same debounce. Hopefully that makes sense.

Script:

--Variables--
local Player = game.Players.LocalPlayer
local char = Player.Character
local en = true
local den = true
--Services--
local UIS = game:GetService("UserInputService")
--
UIS.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Q then --Get the Q button--
if not en then return end--Debounces--
if not den then return end--Debounces--
    den = false
en = false
Part = Instance.new("Part")--Creates A part--
Part.Parent = workspace
Part.CFrame = char.Head.CFrame * CFrame.new(0,0,-5)
wait(3)
en = true
    end
end)
--
UIS.InputEnded:Connect(function(Input)--When Let go it will destroy the Part--
    if Input.KeyCode == Enum.KeyCode.Q then
        Part:Destroy()
den = true
    end
end)
--
UIS.InputBegan:Connect(function(Input)--Basically same thing but with a different Debounce--
    if Input.KeyCode == Enum.KeyCode.E then
    if not den then return end
    if not en then return end
        en = false
den = false
 Part2 = Instance.new("Part")
Part2.Parent = workspace
Part2.CFrame = char.Head.CFrame * CFrame.new(0,0,-5)
wait(3)
den = true
    end
end)
--
UIS.InputEnded:Connect(function(Input)--When let go it will destroy the part
    if Input.KeyCode == Enum.KeyCode.E then
        Part2:Destroy()
en = true
    end
end)
0
You just need a simple flag that is set when you spawn the part then only on InputEnded set the flag back to false. Use only one event listener as well. If the flag is true on inputbegan then return the function block. Impacthills 223 — 6y
0
I'm on my mobile and I'm working atm. If you need any more help when I get to my desktop I can help more. Impacthills 223 — 6y

1 answer

Log in to vote
0
Answered by
waifuSZN 123
6 years ago

Create a boolean value and during your events check whether the boolean is false before creating a part, and if it is NOT false do nothing.

0
Its already doing that GGButNO_RE 61 — 6y
Ad

Answer this question