Im trying to make a script where a GUI enables if you get a certain value
This value is stored in leaderstats and is datastored
Here is my script for the GUI:
local Screen = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local player = game.Players.LocalPlayer
if player.leaderstats.Wins.Value >= 10 then
Screen.Enabled = true
print("Enabled!")
else
print("Nothing")
end
Use a loop to check every 1 or so seconds. Such as:
local Screen = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local player = game.Players.LocalPlayer
spawn(function()
while task.wait(1) do
if player.leaderstats.Wins.Value >= 10 then
Screen.Enabled = true
print("Enabled!")
else
print("Nothing")
end
end
end)
Also, make the frames inside the screengui visible if you arenât. You can use
for _, gui in pairs(Screen:GetChildren()) do
if gui:IsA("Frame") or gui.ClassName:match('Text') then
gui.Visible = true;
-- any text label, box, button or frame will be visible.
end
end
Itâs better to listen whenever the Wins value changes rather than using a loop and spawning a new thread
local Screen = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local player = game.Players.LocalPlayer
local wins = player.leaderstats.Wins
wins:GetPropertyChangedSignal("Value"):Connect(function()
if wins.Value >= 10 then
Screen.Enabled = true
print("Enabled!")
else
print("Nothing")
end
end)
Inside the controller of the whole system. Inside the GUI wouldnât work as the GUI isnât enabled. You could enable it by default, and just make the frame visible instead, and store the script inside of it.
Better yet, use the objectâs âChangedâ event/signal instead.
Wins.Changed:Connect(function(Value) --Value here represents the new value of the 'Wins' object.
if Value > 9 then
--Do code.
else
--Do other code.
end
end)