Why my datastore doesn't work

You can write your topic however you want, but you need to answer these questions:

  1. I tried to sue tonumber and tostring both didn’t work

  2. I got “Unable to cast value to object” error

  3. i tried chatgpt and devforum but nothing i can get

image

local dataStoreService = game:GetService("DataStoreService")
local playerData = dataStoreService:GetDataStore("ashsgfjhlsfvjsafv")
local LoadEvent = script.Load.Event.Value


game.Players.PlayerAdded:Connect(function(player)
	
	local MainTheme = workspace.MainTheme:Clone()
	MainTheme.Parent = player
	MainTheme.Playing = false
	
	local Playing = Instance.new("BoolValue")
	Playing.Parent = player
	Playing.Value = false
	Playing.Name = "Playing"
	
	local CheckPoint = Instance.new("IntValue")
	CheckPoint.Name = "CheckPoint"
	CheckPoint.Parent = player

    --here is the error
	CheckPoint.Value = playerData:GetAsync(player.UserId, player.CheckPoint.Value) or 0
	--ends here
end)

game.Players.PlayerRemoving:Connect(function(player)
	playerData:SetAsync(player.UserId, player.CheckPoint.Value)
	print(player.CheckPoint.Value)
end)

Datastore:GetAsync() only takes one argument, which is the player’s UserId.

Try:

--here is the error
	CheckPoint.Value = playerData:GetAsync(player.UserId) or 0
	--ends here
1 Like

Oh yea thank you buddy for the help that was really annoying.

1 Like

Also just some general advice, wrap any DataStoreService functions within a pcall.

can you give me an exmaple i dont know

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