DataSave for billboard still not working

sometime ago i asked help for datasaving a billboardgui but its not working 100% in fact this is the script:

local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")

game.Players.PlayerRemoving:Connect(function(player)
	local success, err = pcall(function()
		local profile = player.Character.Head:FindFirstChild("profile")
		if profile then
			local image = profile.ImageLabel
			local profileData = {
				arcVisible = image:FindFirstChild("arc").Visible,
				macVisible = image:FindFirstChild("mac").Visible,
				bestVisible = image:FindFirstChild("best").Visible,
				crVisible = image:FindFirstChild("cr").Visible,
				nmsVisible = image:FindFirstChild("nms").Visible,
				r6animatorVisible = image:FindFirstChild("r6animator").Visible,
				runnerVisible = image:FindFirstChild("runner").Visible,
				staffVisible = image:FindFirstChild("staff").Visible,
				starVisible = image:FindFirstChild("star").Visible,
				testerVisible = image:FindFirstChild("tester").Visible,
				v1Visible = image:FindFirstChild("v1").Visible,
				v2Visible = image:FindFirstChild("v2").Visible,
				ytVisible = image:FindFirstChild("yt").Visible,
				TextLabelVisible = image:FindFirstChild("TextLabel").Visible,
				subText = image:FindFirstChild("sub").Text,
				subColor = image:FindFirstChild("sub").TextColor3,
				ImageLabelImage = image.Image
			}

			playerDataStore:SetAsync(player.UserId, profileData)
		end
	end)
	if not success then
		warn("Failed to save player data: " .. tostring(err))
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	local success, data = pcall(function()
		return playerDataStore:GetAsync(player.UserId)
	end)

	if success and data then
		local profile = player.Character.Head:FindFirstChild("profile")
		if profile then
			local image = profile.ImageLabel
			image:FindFirstChild("arc").Visible = data.arcVisible
			image:FindFirstChild("mac").Visible = data.macVisible
			image:FindFirstChild("best").Visible = data.bestVisible
			image:FindFirstChild("nms").Visible = data.nmsVisible
			image:FindFirstChild("tester").Visible = data.testerVisible
			image:FindFirstChild("cr").Visible = data.crVisible
			image:FindFirstChild("r6animator").Visible = data.r6animatorVisible
			image:FindFirstChild("runner").Visible = data.runnerVisible
			image:FindFirstChild("star").Visible = data.starVisible
			image:FindFirstChild("v1").Visible = data.v1Visible
			image:FindFirstChild("v2").Visible = data.v2Visible
			image:FindFirstChild("yt").Visible = data.ytVisible
			image:FindFirstChild("staff").Visible = data.staffVisible
			image:FindFirstChild("TextLabel").Visible = data.TextLabelVisible
			image.Image = data.ImageLabelImage
			image:FindFirstChild("sub").Text = data.subText
			image:FindFirstChild("sub").TextColor3 = data.subColor
		end
	end
end)

here is the order in explorer
Screenshot 2024-03-30 231023

and this is how it should save/how i wanted it to save by customizing the billboard with buttons
Screenshot 2024-03-31 103802

and this is how it looks after leaving and rejoining
Screenshot 2024-03-31 103741

can anyone help me please? i cant find any solution

3 Likes

Maybe add a bind to close into it?

2 Likes

It’s possible that the script isn’t finding the character, as the script does not yield for the character to load in.

Maybe try changing the profile variable to this:

local character = player.Character or player.CharacterAdded:Wait()
local profile = character.Head:FindFirstChild("profile")

EDIT: After further review and testing, I noticed that your key value in your SetAsync() and GetAsync() is only the player.UserId and nothing else. In case there are multiple values in your DataStore (which there generally are), it would be better practice to include a string attached to the UserId:

playerDataStore:SetAsync(player.UserId.."ProfileData", profileData)

Now the actual issue seems to be with saving the profileData table. I can’t seem to figure out why, but will keep messing around with it. The table is created, but it either isn’t being gotten (GetAsync()) or it isnt getting set (SetAsync()).

I will keep you updated with what I find out.

yeah in the datastore i’ve 3 values saving when a player leaves and rejoin, i’ve applied ur changes in the script now it looks like this

local DataStoreService = game:GetService("DataStoreService")
local playerDataStore = DataStoreService:GetDataStore("PlayerData")

game.Players.PlayerRemoving:Connect(function(player)
	local success, err = pcall(function()
		local profile = player.Character.Head:FindFirstChild("profile")
		if profile then
			local character = player.Character or player.CharacterAdded:Wait()
			local profile = character.Head:FindFirstChild("profile")
			local image = profile.ImageLabel
			local profileData = {
				arcVisible = image:FindFirstChild("arc").Visible,
				macVisible = image:FindFirstChild("mac").Visible,
				bestVisible = image:FindFirstChild("best").Visible,
				crVisible = image:FindFirstChild("cr").Visible,
				nmsVisible = image:FindFirstChild("nms").Visible,
				r6animatorVisible = image:FindFirstChild("r6animator").Visible,
				runnerVisible = image:FindFirstChild("runner").Visible,
				staffVisible = image:FindFirstChild("staff").Visible,
				starVisible = image:FindFirstChild("star").Visible,
				testerVisible = image:FindFirstChild("tester").Visible,
				v1Visible = image:FindFirstChild("v1").Visible,
				v2Visible = image:FindFirstChild("v2").Visible,
				ytVisible = image:FindFirstChild("yt").Visible,
				TextLabelVisible = image:FindFirstChild("TextLabel").Visible,
				subText = image:FindFirstChild("sub").Text,
				subColor = image:FindFirstChild("sub").TextColor3,
				ImageLabelImage = image.Image
			}

			playerDataStore:SetAsync(player.UserId.."ProfileData", profileData)
		end
	end)
	if not success then
		warn("Failed to save player data: " .. tostring(err))
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	local success, data = pcall(function()
		return playerDataStore:GetAsync(player.UserId)
	end)

	if success and data then
		local profile = player.Character.Head:FindFirstChild("profile")
		if profile then
			local image = profile.ImageLabel
			image:FindFirstChild("arc").Visible = data.arcVisible
			image:FindFirstChild("mac").Visible = data.macVisible
			image:FindFirstChild("best").Visible = data.bestVisible
			image:FindFirstChild("nms").Visible = data.nmsVisible
			image:FindFirstChild("tester").Visible = data.testerVisible
			image:FindFirstChild("cr").Visible = data.crVisible
			image:FindFirstChild("r6animator").Visible = data.r6animatorVisible
			image:FindFirstChild("runner").Visible = data.runnerVisible
			image:FindFirstChild("star").Visible = data.starVisible
			image:FindFirstChild("v1").Visible = data.v1Visible
			image:FindFirstChild("v2").Visible = data.v2Visible
			image:FindFirstChild("yt").Visible = data.ytVisible
			image:FindFirstChild("staff").Visible = data.staffVisible
			image:FindFirstChild("TextLabel").Visible = data.TextLabelVisible
			image.Image = data.ImageLabelImage
			image:FindFirstChild("sub").Text = data.subText
			image:FindFirstChild("sub").TextColor3 = data.subColor
		end
	end
end)

i’m not sure it’s 100% correct, in case if you don’t mind send me the final script once you’ve found a way to make the datasave work, i’ll apprecciate it sm

1 Like