I'll try to word this constructive to others as well. I'm working with a generic Data Save script to save money (Dollars). Just a normal DataStore to keep a players money the same when the disconnect and reconnect. I have the code in a NORMAL SCRIPT in the workspace, but when I run the game I get no errors but the money does not save so I manually run the script and it says, "DataStore can't be accessed from client". I'm not sure what this means, it would be awesome if someone could clarify the error or see if theres an error in the code. Thanks a ton.

local DSS = game:GetService('DataStoreService'):GetDataStore('TestingTesting123')
game.Players.PlayerAdded:Connect(function(plr)
	local unique = 'id-'..plr.userId
	local leaderstats = Instance.new('IntValue',plr)
	local savevalue = Instance.new('IntValue',leaderstats)
	leaderstats.Name = "leaderstats"
	savevalue.Parent = leaderstats
	savevalue.Name = "Dollars"
	leaderstats.Value = 10
	
	
	local GetSaved = DSS:GetAsync(unique)
	if GetSaved then
		savevalue.Value = GetSaved[1]
	else
		local NumbersForSaving = {savevalue.Value}
		DSS:SetAsync(unique, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local unique = 'id-'..plr.userId
	local Savetable = {plr.leaderstats.Dollars.Value}
	DSS:SetAsync(unique, Savetable)
end)

3 comments

0

Scripts in studio test run locally. You should test in a test server or try it in-game

0

thank u I will try that.

0

It worked thank you!