So I am trying to create GUI for an ability, and have it change for a cooldown.
I am using this code to make the changes:
Summary
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local DashState = character:WaitForChild("Dash")
local DashGUI = game.StarterGui.DashGui
DashState.Changed:Connect(function()
if DashState.Value == true then
print("value true")
DashGUI.GreenCircle.Visible = false
end
if DashState.Value == false then
print("value false")
DashGUI.GreenCircle.Visible = true
end
end)
I know that it is working because the Print functions are being printed; however, the GUI is not disappearing like it should.
Can anyone give me some insight on why I may be having this problem?
Edit:
This is how my GUI is structured, and where the script is.
From what I can see, You’re trying to set from StarterGui which is wrong if you are trying to replicate it only on the client. If you want to make it work try using
local player = game:GetService("Players").LocalPlayer
local character = player.Character
local DashState = character:WaitForChild("Dash")
-- Using PlayerGui will make it work "possibly"
local DashGUI = player.PlayerGui:FindFirstChild("DashGui") -- Or you can use WaitForChild()
DashState.Changed:Connect(function()
if DashState.Value == true then
print("value true")
DashGUI.GreenCircle.Visible = false
end
if DashState.Value == false then
print("value false")
DashGUI.GreenCircle.Visible = true
end
end)
This, and in addition he also needs to use elseif, otherwise the GUI will always go back to visible.
if DashState.Value == true then -- If it's true then
print("value true")
DashGUI.GreenCircle.Visible = false -- Make it false
end -- So now, if it was true, it's false. If it was false, it's false.
if DashState.Value == false then -- It's false.
print("value false")
DashGUI.GreenCircle.Visible = true -- Make it true.
end -- So now, it's always true.
This is what you want.
if DashState.Value == true then
print("value true")
DashGUI.GreenCircle.Visible = false
elseif DashState.Value == false then
print("value false")
DashGUI.GreenCircle.Visible = true
end