Save slot GUI not showing player stats

You can write your topic however you want, but you need to answer these questions:
Hey everyone I’m working on a main menu GUI with save/load slots and it current loads/saves the player’s data as intended, but I want the slots on the main menu to show the players stats from the different datastores (Stats2,Stats3,Stats4,Stats5,Stats6). The problem is I can’t seem to get the player’s values from the different datastores to populate the GUI, I’ve even added message blocks into my script to let me know if anything is failing and I get nothing and zero error messages as well. Below is the local script that is inside my menu GUI and a short clip of the issue. All I’m looking for is a way to pull values from exsisting datastores to my GUI so players can see exactly what slot they’re loading into.

-- local frame = script.Parent
local Slot1 = frame.LOAD1
local Slot2 = frame.LOAD2
local Slot3 = frame.LOAD3
local Slot4 = frame.LOAD4
local Slot5 = frame.LOAD5
local BackB = frame.Back
local Gold1 = frame.Gold1
local Gold2 = frame.Gold2
local Gold3 = frame.Gold3
local Gold4 = frame.Gold4
local Gold5 = frame.Gold5
local Level1 = frame.Level1
local Level2 = frame.Level2
local Level3 = frame.Level3
local Level4 = frame.Level4
local Level5 = frame.Level5
local Rank1 = frame.Rank1
local Rank2 = frame.Rank2
local Rank3 = frame.Rank3
local Rank4 = frame.Rank4
local Rank5 = frame.Rank5
local School1 = frame.School1
local School2 = frame.School2
local School3 = frame.School3
local School4 = frame.School4
local School5 = frame.School5

function updateGUI(player)
	local success, data = pcall(function()
		return game:GetService("DataStoreService"):GetDataStore("Stats2"):GetAsync(tostring(player.UserId))
	end)

	if success then
		-- Check if the Gold value is present in the data
		if data and data.Gold ~= nil then
			Gold1.Text = "Gold: " .. data.Gold
		else
			Gold1.Text = "Gold: N/A"
		end
	else
		warn("Failed to load data from DataStore for " .. player.Name)
	end
end

-- Connect to the PlayerAdded event
game.Players.PlayerAdded:Connect(function(player)
	updateGUI(player)
end)

-- Button click events
-- ...

BackB.MouseButton1Click:Connect(function()
	script.Parent.Visible = false
	script.Parent.Parent.Background.Visible = true
end)

Showcase.wmv (771.0 KB)

1 Like

That script won’t work with multiple players.
You are using a server script and you don’t have Gui connected to the player, which means that all players will only see the values of the last player who joined.
I would put the script in “ServerScriptService”, delete all the GUIs and move them to the updateGUI. Leave this script only for loading/saving data, nothing more.
Furthermore, you don’t have to set “Gold: N/A” using a script, but write it there directly (if there is data, it will just be overwritten). Also, you don’t need to check if “Gold ~= nil…” either you have data (where you set everything to “N/A” by default and then you just overwrite), or you have nothing
And for buttonclick functions… Use LocalScript inside StarterGUI and use FireServer functions to connect to the server.

I’ve modified the script to be able to load all the saves:

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

function updateGUI(player)
	local PlayerGui = player.PlayerGui
	local Frame = PlayerGui:WaitForChild(" first folder in playergui/startergui to yours frame")... .frame 
	
	for NumberSaves = 2,6 do -- save2,3,4,5,6
		local success, data = pcall(function()
			return DataStoreService:GetDataStore("Stats"..NumberSaves):GetAsync(tostring(player.UserId))
		end)

		if success then
			if data then
				Frame["School"..NumberSaves-1].Text = "School: " .. data.School -- frame.School1,2,3,4,5,6
				Frame["Level"..NumberSaves-1].Text = "Level: " .. data.Level -- frame.Level1,2,3,4,5,6
				Frame["Rank"..NumberSaves-1].Text = "Rank: " .. data.Rank -- frame.Rank1,2,3,4,5,6
				Frame["Gold"..NumberSaves-1].Text = "Gold: " .. data.Gold	-- frameGold1,2,3,4,5,6		
			end
		else
			warn("Failed to load data from DataStore for " .. player.Name)
		end	
	end
end

Players.PlayerAdded:Connect(function(player)
	updateGUI(player)
end)

And tip, it’s better to have a frame with school1,gold1,rank1,level1,load1, in the next frame there will be school2… in the next school3, it’s easier to work with and you can mainly use functions like UIpadding/UIgrid… to align it and it will look same on all devices.

2 Likes

This was a huge help, I used the server script you provided and made some tweaks and now everything is working perfectly, below is the full script with the changes

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

function updateGUI(player)
	local PlayerGui = player.PlayerGui
	local menu = PlayerGui:WaitForChild("MainMenu")
	local Frame = menu:WaitForChild("LoadSlotsTesting")
	

	for NumberSaves = 2,6 do -- save2,3,4,5,6
		local success, data = pcall(function()
			return DataStoreService:GetDataStore("Stats"..NumberSaves):GetAsync(tostring(player.UserId))
		end)

		if success then
			if data then
				Frame["School"..NumberSaves-1].Text = "School: " .. data.Team -- frame.School1,2,3,4,5,6
				Frame["Level"..NumberSaves-1].Text = "Level: " .. data.Level -- frame.Level1,2,3,4,5,6
				Frame["Rank"..NumberSaves-1].Text = "Rank: " .. data.Rank -- frame.Rank1,2,3,4,5,6
				Frame["Gold"..NumberSaves-1].Text = "Gold: " .. data.Gold	-- frameGold1,2,3,4,5,6		
			end
		else
			warn("Failed to load data from DataStore for " .. player.Name)
		end	
	end
end

Players.PlayerAdded:Connect(function(player)
	updateGUI(player)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.