I am making a Gui that checks for a BoolValue using DataStoreService when a player joins the game.
How this works is, when a player clicks on a TextButton, a TextLabel will become visible and so does a GuiValue inside a folder in the player. When the player leaves the game, the GuiValue saves and remains true. When the player joins back, the GuiValue should still remain true for that player and the TextLabel checks if the GuiValue is true so then the TextLabel should remain visible.
Now here's the problem, when the player joins back into the game, the GuiValue remains True, but the TextLabel's Visibility remains False.
The only error i could find is: " Infinite yield possible on 'Players.Player1.PlayerGui:WaitForChild("SaveScreenGui")' " 'ServerScriptService.GuiDataStore', Line 11 - global loadGuiValue 'ServerScriptService.GuiDataStore', Line 24
Datastore Script in ServerScriptService:
local DSS = game:GetService("DataStoreService"):GetDataStore("GuiStore1") local event = game.ReplicatedStorage.PlayerGuiEvent function saveGuiValue(player) DSS:SetAsync(player.userId, player.GuiFolder.GuiValue.Value) print("Saved Gui Value") end function loadGuiValue(player) player.GuiFolder.GuiValue.Value = DSS:GetAsync(player.userId) local Gui = player:WaitForChild("PlayerGui"):WaitForChild("SaveScreenGui").TextLabel event:FireClient(player, Gui) end function onPlayerEntered(newPlayer) local GuiFolder = Instance.new("Folder", newPlayer) GuiFolder.Name = "GuiFolder" local guiValue = Instance.new("BoolValue", GuiFolder) guiValue.Name = "GuiValue" guiValue.Value = false newPlayer:WaitForDataReady() loadGuiValue(newPlayer) end function onPlayerRemoving(player) local guiValue = player.GuiFolder:FindFirstChild("GuiValue") if (guiValue ~= nil) then saveGuiValue(player) end end game.Players.PlayerAdded:Connect(onPlayerEntered) game.Players.PlayerRemoving:Connect(onPlayerRemoving)
LocalScript inside the button with MouseButton1Click and checks for GuiValue:
local plr = game.Players.LocalPlayer local event = game.ReplicatedStorage.PlayerGuiEvent event.OnClientEvent:Connect(function(plr,Gui) if plr.GuiFolder.GuiValue.Value == true then Gui.Visible = true else Gui.Visible = false end end) script.Parent.MouseButton1Click:Connect(function() local guiValue = plr:WaitForChild("GuiFolder"):FindFirstChild("GuiValue") local TextLabel = plr:WaitForChild("PlayerGui").SaveScreenGui.TextLabel guiValue.Value = true TextLabel.Visible = true end)