How do i fix this script

  1. What do you want to achieve?
    I was trying to make when if textbutton is visible then the gui is not enable

  2. What is the issue?
    The If statement doesent seem to work

local Events = game.ReplicatedStorage.MiscEvents.GuiEvent
local timer = script.parent
local gui = script.parent.parent
local button = game.StarterGui.RadioGui.ImageButton.Frame.TextButton

Events.OnClientEvent:Connect(function()
   gui.Enabled = true
   for i = 10,0,-1 do
         timer.Text = i
   end
   timer.Text = i
end)

if button.Visible == true then
    gui.Enabled = false
end

StarterGUI is copied into PlayerGUI on game launch so you’ll need to get the button reference from PlayerGUI

i have change the script but still it doesent work and also messed up the countdown i think i may have done it wrong?

local Events = game.ReplicatedStorage.MiscEvent.GuiEvent
local Timer = script.Parent
local gui = script.Parent.Parent
local players = game.Players.LocalPlayer
local Radio = players.PlayerGui:WaitForChild("RadioGui")
local button = Radio.ImageButton.Frame.TextButton
local plgui = players.PlayerGui:WaitForChild("CountdownRadio")

Events.OnClientEvent:Connect(function()
	gui.Enabled = true
	for i = 10,0,-1 do
		Timer.Text = i
	end
	Timer.Text = ""
end)

if button.Visible == true then
	plgui.Enabled = false
end

Does the script have any errors?

What is this code suppose to do? From the looks of it, your just trying to make a gui disable.

in proximity prompt i put a script then fireallclient then i used that event in a local script under a countdown gui that if another gui that is visible, which the other gui also use onclientevent, so i want the countdown would end if the other gui is turned visible, yes im making the gui disabled

ive check on output and theres no error

Try this to see if its getting past the if statement

if button.Visible == true then
    print("Passed")
    gui.Enabled = false
end

Nope, this code will only run ONCE when the script is added into the player, and this part of the code will never run again, its not listening, not connected to any event

if button.Visible == true then
    gui.Enabled = false
end

ok it didnt print i dont know why

Thats what you looking for? make the script to disable the gui when the player joined?

oh that part, i thought you meant the countdown, yeah i dont know, but my goal is when the RadioGui textbutton is visible then the CountdownGui disabled, the radio gui is using onclientevent which it only be visible when the proximity prompt gets triggered which i fireallclient, so radiogui would appear but the textbutton didnt until i click another button,then it will be visible, so when it is visible the countdowngui will be disabled

Im sorry I cant understand your explanation.
The code you are showing does this:
When script is added into the player, checks button.Visible, if true, proceeds to disable the gui
And it has a listener, made by OnClientEvent, waiting signal from server to enable gui, then a loop to update a text with a countdown.
And thats all your script does

Yes that is, sorry if i explain it badly

but i dont know why the if statement doesent work

Try this and check output

local Events = game.ReplicatedStorage.MiscEvents.GuiEvent
local timer = script.parent
local gui = script.parent.parent
local button = game.StarterGui.RadioGui.ImageButton.Frame.TextButton

Events.OnClientEvent:Connect(function()
	gui.Enabled = true
	for i = 10,0,-1 do
		timer.Text = i
	end
	--timer.Text = i
end)

if button.Visible == true then
	warn("IM HERE!")
	gui.Enabled = false
end

seeing this code the if statement will only run on startup

Events.OnClientEvent:Connect(function()
	gui.Enabled = true
	for i = 10,0,-1 do
		timer.Text = i
	end
	--timer.Text = i
end)

this part will show the GUI. but won’t hide the button.

Yeah, its what I said, the if statement only run once, its not connected to any event in order to happen again.

You tested the code and found the warn that proves it runs at least once?

If it runs once, then now place the if statement into a function connected to an event when you want to disable the gui when button visibility becomes true.
(I guess, cause I dont understand yet what is the goal)

Make the visibility of the button to control the gui visibility on property changed? or handle it by using the remote.OnClientEvent() (?)