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?
** You are now Level 1! **