My gui data store doesn't work anymore

So, I made a data store where it saves a gui to a data store. For example, when you join the game and make the frame not visible and you rejoin, it stays invisible. And the weird thing is that, the data store works in studio, but not in the final game.

We cannot help if we have no idea what the script looks like. Can you please add it to the post?

can you share us the code? so we have a idea

Oh yeah, sorry about that.

local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")

local frame = game.StarterGui.Save.Frame


players.PlayerAdded:Connect(function(plr)

	local ds = dataStoreService:GetDataStore(tostring(plr.UserId))
	
	local success, response = pcall(function()

		return ds:GetAsync("gui_visible")
	end)
	

	if (success) then
	
		if (response) then
			frame.Visible = true
		else

			frame.Visible = false
		end
	end
end)

players.PlayerRemoving:Connect(function(plr)

	local ds = dataStoreService:GetDataStore(tostring(plr.UserId))

	ds:SetAsync("gui_visible", frame.Visible)
end)

So, it appears you used the player’s user id as the data store, instead of the key to the data store. This can cause some issues. Like, when you’re saving the data store it has no key or an incorrect one. I’m not sure, this code looks a little confusing. (Because you’re doing strange stuff like having the gui being visible as the thing you’re saving, and it will have the result for every player because the key isn’t a player’s userid and doesn’t apply to certain userids because the key is just if it’s visible.)

I see a problem and a thing that you could do better

The Problem is that your currently using Game.starterGui and not Player.PlayerGui

The thing that you could do better is to only use one datastore and save the userdata under a spesific key like the players id, read @ImTheBuildGuy’s response it a good one

1 Like

This worked before. But now it just doesn’t work. And I didn’t change a single line of code.

Roblox will update how codes work. That’s why very old games that haven’t been updated in a long time are almost always broken. I think that happend to your code. It’s outdated.

But I wrote the code a month ago. And the code still works in studio.

Wait! Do you have the Datastore API enabled in your game's settings?

Here is a video that might help you understand what we are talking about when we say that you should use one datastore instead of one fore every user

Yeah. I do have API enabled in my game settings.

Yes but that includes datastores, which can help you.