This doesnt work for some reason

hello

  1. What do you want to achieve? I want to have this save script save your head size through the leaderstats script

  2. What is the issue? I cannot save the leaderstats nor the head size

  3. What solutions have you tried so far? I looked at tutorials, the devforum, and the toolbox

  4. Ask me anything, I can try to answer

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("playerData")

local Players = game:GetService("Players")


Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		--making leaderstats
		task.spawn(function()
			while task.wait() do 
				HeadSize.Value = Character.Head.Size.Magnitude
				end
				end)
				local data 
				local success, errormessage = pcall(function()
					data = playerData:GetAsync(Player.UserId.."-HeadSize") 
				end)
				if success then 
					HeadSize.Value = data
				else
					print("Error while getting your data")
					warn(errormessage)
				end
			end)
end)	
Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall(function()
		playerData:SetAsync(player.UserId.."-HeadSize", player.leaderstats.Value.Value)
	end)

	if success then
		print("Data successfully saved!")
	else
		print("There was an error while saving the data")
		warn(errormessage)
	end
end)
		
		
		thankth alot for reading
	
1 Like
  1. Where’s the leaderstats?
  2. You typed in the SetAsync value Value.Value
  3. Make sure API services are on…
1 Like

Have that, didnt wanna show it

What should I type instead?

Im smart enough to know that

1 Like

whats the point of making a leaderstats folder every time the character respawns?

using :GetAsync repeatly can cause a lot of lag, there is no point (especially in your code)

whole code block is messed up

2 Likes

didnt know that, where do I put it

any alternatives?

you’re too kind

1 Like

If you want some easy-to-use alternatives to Datastores in general that are really simple i’d suggest:

or

you only have to create a leaderstats folder joins the game, or Player.PlayerAdded. The leaderstats doesn’t delete or go anywhere whenever the character respawns or dies

1 Like