#UI TextButton only working 50% of the time?

25 messages · Page 1 of 1 (latest)

keen wyvern
#

I have a script inside my GUI (RoundBriefUI), that runs when the remote event 'RoundBrief' is fired. When fired, the UI pops up. Then, there is a button that you can press to Start the round, firing another remote event called 'RoundBegin'. 50% of the time, when I press the button, the UI disables (as it should) but the event doesnt fire. The other 50% of the time it fires, and theres no issues.

if not game:GetService("RunService"):IsClient() then return end

local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")

-- Ensure the character is loaded
if not player.Character then
    player.CharacterAdded:Wait()
end

local playerGui = player:WaitForChild("PlayerGui")
local GUI = playerGui:WaitForChild("RoundBriefUI")

local BackgroundFrame = GUI:WaitForChild("BackgroundFrame")
local TargetFrame = GUI:WaitForChild("TargetFrame")
local TextButton = GUI:WaitForChild("TextButton")
local BriefText = GUI:WaitForChild("BriefText")
local TargetText = GUI:WaitForChild("TargetText")

local RoundBriefEvent = ReplicatedStorage:WaitForChild("RoundBrief")
local RoundBeginEvent = ReplicatedStorage:WaitForChild("RoundBegin")

local debounce = false

local function initializeGUIElements()
    BackgroundFrame.Visible = false
    BriefText.Visible = false
    TextButton.Visible = false
    TargetText.Visible = false
    TargetFrame.Visible = false

    BriefText.TextTransparency = 1
    TargetText.TextTransparency = 1
    TextButton.TextTransparency = 1
    TextButton.BackgroundTransparency = 1

    GUI.Enabled = false
end

local function fadeIn(element, duration)
    for i = 0, 1, RunService.RenderStepped:Wait() / duration do
        element.TextTransparency = 1 - i
        if element:IsA("TextButton") then
            element.BackgroundTransparency = 1 - i
        end
    end
    element.TextTransparency = 0
    if element:IsA("TextButton") then
        element.BackgroundTransparency = 0
    end
end

local function RoundBriefEventFunction()
    BackgroundFrame.Visible = true
    BriefText.Visible = true
    TextButton.Visible = true
    TargetText.Visible = true
    TargetFrame.Visible = true

    GUI.Enabled = true
    UIS.MouseIconEnabled = true

    coroutine.wrap(fadeIn)(BriefText, 0.5)
    coroutine.wrap(fadeIn)(TextButton, 0.5)
    coroutine.wrap(fadeIn)(TargetText, 0.5)
end

initializeGUIElements()
RoundBriefEvent.OnClientEvent:Connect(RoundBriefEventFunction)

local function onTextButtonPressed()
    if debounce then return end
    debounce = true

    GUI.Enabled = false
    UIS.MouseIconEnabled = false

    RoundBeginEvent:FireServer()

    task.delay(0.2, function()
        debounce = false
    end)
end

TextButton.MouseButton1Click:Connect(onTextButtonPressed)

Anyone know where I'm going crazy?

valid rain
#

i dont wanna read allat, so just add a print to the .Onclientevent

#

and see if it prints

keen wyvern
#

It's this portion:

local function onTextButtonPressed()
    if debounce then return end
    debounce = true

    GUI.Enabled = false
    UIS.MouseIconEnabled = false

    RoundBeginEvent:FireServer()

    task.delay(0.2, function()
        debounce = false
    end)
end

TextButton.MouseButton1Click:Connect(onTextButtonPressed)```
#

Only like 50% of the time, RoundBeginEvent fires, and I have no clue why. Could go into test, it would work, stop, test again, and now it doesnt work

valid rain
keen wyvern
#

Trying now

valid rain
#

try commenting the debounce for now and see if the event will fire every time

keen wyvern
#

So I made this change:

local function onTextButtonPressed()
    if debounce then 
        print("Debounce is active, ignoring click")
        return 
    end
    debounce = true

    GUI.Enabled = false
    UIS.MouseIconEnabled = false

    print("Firing RoundBeginEvent")
    RoundBeginEvent:FireServer()

    task.wait(0.2)
    debounce = false
    print("Debounce reset")
end


TextButton.MouseButton1Click:Connect(onTextButtonPressed)

Heres the output:

03:30:28.704 Firing RoundBeginEvent - Client - RoundBriefHandler:86
03:30:28.705 Firing RoundBeginEvent - Studio
03:30:28.907 Debounce reset - Client - RoundBriefHandler:91
03:30:28.907 Debounce reset - Studio

#

If you want, I can show you my EventHandler serverscript

#

But i havent had any other issues with any other scripts Firing so idk wtf is up

valid rain
#

like else?

keen wyvern
#

No, because when ive added print statements, they would still print at the front and end of the function with no issues, so i assumed it had to do me something crazy im missing

rancid ravenBOT
#

studio** You are now Level 1! **studio

valid rain
timid vortex
#

It happens when there is a button over a button

snow yacht
#

why dose this not work?

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.StarterGui.ScreenGui.Uppgrades.Visible = true
end
end)

timid vortex
#

use playergui