My english is really bad but I still hope you can understand me
I think the title should explain it too.
Hey, I make a random click system, but the problem is: When I try to click it many times it just hang and nothing happens. It means I need to click many times untill anything happens.
Again, it does work but sometimes when I click many times then it just stop out and then I have to wait like 0.5sec untill it does work again.
Here a video for visualize;
This is the script:
local UserInputService = game:GetService('UserInputService')
local Keys = {
Enum.KeyCode.J,
Enum.KeyCode.H
}
local TextButton = script.Parent.Frame.TextButton
local CurrentKey
local function setRandomKey()
CurrentKey = Keys[math.random(1, #Keys)]
TextButton.Text = string.char(CurrentKey.Value):upper()
end setRandomKey()
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == CurrentKey then
print('Correct key')
setRandomKey()
else
print('false')
end
end)
I love this community really and I am so happy for getting so much help really thanks ;D!
local UserInputService = game:GetService('UserInputService')
local Keys = {"J","H"}
local debounce = true
local TextButton = script.Parent.Frame.TextButton
TextButton.Text = Keys[math.random(#Keys)]
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode[TextButton.Text] and debounce then
debounce = false
print('Correct key')
TextButton.Text = Keys[math.random(#Keys)]
debounce = true
else print('false') end
end
end)
This is better but it does still lag after many correct keys and false keys. The player should be able to make it correct after He did it false. Try it fast and you will see it lags
You might have to change this depending on your script but:
local CurrentKey = "J"
local AvailableKeys = {"J","H"}
repeat
local NextKey = AvailableKeys[math.random(1, #AvailableKeys)]
until NextKey ~= CurrentKey
My bad I wrote this script before I saw your reply. Well if you ever need to check for duplication, atleast you know how now!