Saving a players avatar that they made in-game not working

So I am making an in-game avatar editor and its going pretty well so far. But I am stuck on how to save their avatars. So what I tried so far was using a check mark (it goes visible when a player clicks a TextButton, which the check mark is a child of) . So like how i wanted it to work was: When player clicks a shirt, hat, or skin tone. it’ll give it to them and a check mark GUI will get toggled on in the corner of the button indicating that it was a success. And one of the children of the check mark is a BoolValue. and I was going to make a datastore saving that boolvalue. Then making another script, I’ll put it to wait for the boolvalue to load, then when it loads, it’ll check if its true/false, if its true it’ll give that specific hat/shirt/pant/skintone to the player.
PROBLEM
First off, its not saving the boolValue so I can’t check if the player has had the hat before.
And I checked all over the place on how to save boolValues. Nothing so far. Plus, I don’t know how to save multiple of them :confused:

--This is the script that is suppose to save the boolValues
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	
	local success, errormessage = pcall(function()
		MyDataStore:GetAsync(player.UserId)
	end)
	if success then
		print("gotdataboi")
	else
		warn(errormessage)
	end
	
	
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		MyDataStore:SetAsync(player.UserId,{
			skintone1 = game.StarterGui.Menu.Frame1.SkinTone1.check1:WaitForChild("Value").Value,
			skintone2 = game.StarterGui.Menu.Frame1.SkinTone2.check2:WaitForChild("Value").Value,
			skintone3 = game.StarterGui.Menu.Frame1.SkinTone3.check3:WaitForChild("Value").Value,
			skintone4 = game.StarterGui.Menu.Frame1.SkinTone4.check4:WaitForChild("Value").Value,
			skintone5 = game.StarterGui.Menu.Frame1.SkinTone5.check5:WaitForChild("Value").Value,
			skintone6 = game.StarterGui.Menu.Frame1.SkinTone6.check6:WaitForChild("Value").Value
		})
	end)
	if success then
		print("datasaved")
	else
		warn(errormessage)
	end
end)
game:BindToClose(function()
	for _, plr in pairs(game.Players:GetPlayers()) do
		
		local success, errormessage = pcall(function()
			MyDataStore:SetAsync(plr.UserId,{
				skintone1 = game.StarterGui.Menu.Frame1.SkinTone1.check1:WaitForChild("Value").Value,
				skintone2 = game.StarterGui.Menu.Frame1.SkinTone2.check2:WaitForChild("Value").Value,
				skintone3 = game.StarterGui.Menu.Frame1.SkinTone3.check3:WaitForChild("Value").Value,
				skintone4 = game.StarterGui.Menu.Frame1.SkinTone4.check4:WaitForChild("Value").Value,
				skintone5 = game.StarterGui.Menu.Frame1.SkinTone5.check5:WaitForChild("Value").Value,
				skintone6 = game.StarterGui.Menu.Frame1.SkinTone6.check6:WaitForChild("Value").Value
			})
		end)
		if succes then
			print("datasaved")
		else
			warn(errormessage)
		end
	end
end)

So yeah its not working. And to say it again: Im trying to save a players avatar that they made(ex; skin tones, shirts/pants, hats that they had on.) And on this one I was saving the skintone that they chose.
And in a another script I was going to make the check mark GUI on/off depending on if the bool value was true/false.
So yeah. Nothings working. Is there something I am doing wrong? Is there a different way to save multiple BoolValues?

1 Like

That is the issue, a Value cannot change in a LocalScript. Instead, try using a Script to change the Value. You will need to use RemoteEvent or RemoteFunction and Fire to the Server side.

--LocalScript
local textButton --the button
local remoteEvent --the remote event you fire to
local booleanvalue --true or false value under the button
textButton.MouseButton1Click:Connect(function()
     remoteEvent:FireServer(booleanvalue.Value)
end
------------------------------------
--Script
remoteEvent.OnServerEvent:Connect(function(player, val)
     if val then
          booleanvalue.Value = false --booleanvalue is the value under the button
     else
          booleanvalue.Value = true
     end
end)

Wow thanks, I moved on to finish the main-menu meanwhile people would respond. This will 100% work i bet. I’ll put this post as solved when i go back an complete the avatar system. Thanks so much!

1 Like