Help making my data store load the saved data

I want to get this working so i can get one of my games hopefully out soon
I cant seem to figure out how to make this fully work
I have look for a solution on the developer hub and could not find one.

if any one could help me figure out what i did wrong and provide feed back and tips that would much apreacated

here is the main datastore script code

Select me for the main code
local datastoreservice = game.DataStoreService
local moneydatastore = datastoreservice:GetDataStore("playersfunds","playerid")
local housewhitlist = datastoreservice:GetDataStore("guestlist","playerid")
local ammodatastore = datastoreservice:GetDataStore("playersammmostockpile","playerid")
local resourcesdatastore = datastoreservice:GetDataStore("playersresources","playerid")
local ammotable = {}
local pid = ""
local potatotable = {}
local upid = ""

do
	-- This is your secret 67-bit key (any random bits are OK)
	local Key53 = 8186484168865098
	local Key14 = 4887

	local inv256

	function encode(str)
		if not inv256 then
			inv256 = {}
			for M = 0, 127 do
				local inv = -1
				repeat inv = inv + 2
				until inv * (2*M + 1) % 256 == 1
				inv256[M] = inv
			end
		end
		local K, F = Key53, 16384 + Key14
		return (str:gsub('.',
			function(m)
				local L = K % 274877906944  -- 2^38
				local H = (K - L) / 274877906944
				local M = H % 128
				m = m:byte()
				local c = (m * inv256[M] - (H - M) / 128) % 256
				K = L * F + H + c + m
				return ('%02x'):format(c)
			end
			))
	end

	function decode(str)
		local K, F = Key53, 16384 + Key14
		return (str:gsub('%x%x',
			function(c)
				local L = K % 274877906944  -- 2^38
				local H = (K - L) / 274877906944
				local M = H % 128
				c = tonumber(c, 16)
				local m = (c + (H - M) / 128) * (2*M + 1) % 256
				K = L * F + H + c + m
				return string.char(m)
			end
			))
	end
end

































script.prlrevome.OnServerEvent:Connect(function(sunshine,gumdrops)
	print(sunshine,gumdrops)
	local	splitdata = 	string.split(gumdrops," ")	
	print(splitdata)
	for dataid,data in pairs(splitdata) do
		table.insert(ammotable,dataid,data)
	end

	print(ammotable)
	pid = sunshine.UserId
	
	wait(.1)
	ammodatastore:SetAsync(pid,ammotable)

end)

game.Players.PlayerAdded:Connect(function(player)
	local geter = ammodatastore:GetAsync(tostring(player.UserId))
	print(geter)
	print("working")
end)

script.RemoteEvent.OnServerEvent:Connect(function(plr,plrid,datatable)
	print(datatable)
	
	
	

	for dataid,data in pairs(datatable) do
		table.insert(ammotable,dataid,data)
	end
	
	print(ammotable)
	pid = plrid
end)

repeat wait() until pid ~= ""
ammodatastore:SetAsync(pid,ammotable)
wait(1)
pid = ""


1 Like

If you are getting any errors, please list them. also i would like to know what the decode and encode functions are for. Also you use :GetService() for things like the DataStoreService

well i am not getting any errors.

it just does not want to work

Ive looked over it and I just cant understand it, hope you find a solution, best of luck!

maybe seeing the hierarch of where the script is might help

why is the script in starterplayerscripts

because that is where i put the ammo storage to begin with

here is the log part for the player removing and the periodic data save

1  -  Client - LocalScript:109
  2  -  Client - LocalScript:109
  3  -  Client - LocalScript:109
  4  -  Client - LocalScript:109
  5  -  Client - LocalScript:109
  6  -  Client - LocalScript:109
  7  -  Client - LocalScript:109
  8  -  Client - LocalScript:109
  9  -  Client - LocalScript:109
  10  -  Client - LocalScript:109
  11  -  Client - LocalScript:109
  12  -  Client - LocalScript:109
  13  -  Client - LocalScript:109
  14  -  Client - LocalScript:109
  15  -  Client - LocalScript:109
  16  -  Client - LocalScript:109
  17  -  Client - LocalScript:109
  18  -  Client - LocalScript:109
  19  -  Client - LocalScript:109
  20  -  Client - LocalScript:109
  21  -  Client - LocalScript:109
  22  -  Client - LocalScript:109
  23  -  Client - LocalScript:109
  24  -  Client - LocalScript:109
  25  -  Client - LocalScript:109
  26  -  Client - LocalScript:109
  27  -  Client - LocalScript:109
   ▼  {
    [1] = "08",
    [2] = "08",
    [3] = "08",
    [4] = "08",
    [5] = "c170175f",
    [6] = "08",
    [7] = "08",
    [8] = "08",
    [9] = "08",
    [10] = "08",
    [11] = "08",
    [12] = "08",
    [13] = "08",
    [14] = "08",
    [15] = "08",
    [16] = "08",
    [17] = "08",
    [18] = "08",
    [19] = "08",
    [20] = "08",
    [21] = "08",
    [22] = "08",
    [23] = "08",
    [24] = "08",
    [25] = "08",
    [26] = "08",
    [27] = "08"
  }  -  Client
   ▼  {
    [1] = "08",
    [2] = "08",
    [3] = "08",
    [4] = "08",
    [5] = "c170175f",
    [6] = "08",
    [7] = "08",
    [8] = "08",
    [9] = "08",
    [10] = "08",
    [11] = "08",
    [12] = "08",
    [13] = "08",
    [14] = "08",
    [15] = "08",
    [16] = "08",
    [17] = "08",
    [18] = "08",
    [19] = "08",
    [20] = "08",
    [21] = "08",
    [22] = "08",
    [23] = "08",
    [24] = "08",
    [25] = "08",
    [26] = "08",
    [27] = "08"
  }  -  Server
   ▼  {
    [1] = "08",
    [2] = "08",
    [3] = "08",
    [4] = "08",
    [5] = "c170175f",
    [6] = "08",
    [7] = "08",
    [8] = "08",
    [9] = "08",
    [10] = "08",
    [11] = "08",
    [12] = "08",
    [13] = "08",
    [14] = "08",
    [15] = "08",
    [16] = "08",
    [17] = "08",
    [18] = "08",
    [19] = "08",
    [20] = "08",
    [21] = "08",
    [22] = "08",
    [23] = "08",
    [24] = "08",
    [25] = "08",
    [26] = "08",
    [27] = "08"
  }  -  Server
  1  -  Client - LocalScript:79
  2  -  Client - LocalScript:79
  3  -  Client - LocalScript:79
  4  -  Client - LocalScript:79
  5  -  Client - LocalScript:79
  6  -  Client - LocalScript:79
  7  -  Client - LocalScript:79
  8  -  Client - LocalScript:79
  9  -  Client - LocalScript:79
  10  -  Client - LocalScript:79
  11  -  Client - LocalScript:79
  12  -  Client - LocalScript:79
  13  -  Client - LocalScript:79
  14  -  Client - LocalScript:79
  15  -  Client - LocalScript:79
  16  -  Client - LocalScript:79
  17  -  Client - LocalScript:79
  18  -  Client - LocalScript:79
  19  -  Client - LocalScript:79
  20  -  Client - LocalScript:79
  21  -  Client - LocalScript:79
  22  -  Client - LocalScript:79
  23  -  Client - LocalScript:79
  24  -  Client - LocalScript:79
  25  -  Client - LocalScript:79
  26  -  Client - LocalScript:79
  27  -  Client - LocalScript:79
   ▼  {
    [1] = "08",
    [2] = "08",
    [3] = "08",
    [4] = "08",
    [5] = "c170175f",
    [6] = "08",
    [7] = "08",
    [8] = "08",
    [9] = "08",
    [10] = "08",
    [11] = "08",
    [12] = "08",
    [13] = "08",
    [14] = "08",
    [15] = "08",
    [16] = "08",
    [17] = "08",
    [18] = "08",
    [19] = "08",
    [20] = "08",
    [21] = "08",
    [22] = "08",
    [23] = "08",
    [24] = "08",
    [25] = "08",
    [26] = "08",
    [27] = "08"
  }  -  Client

I dont understand the way you have it working so the best thing i can do is wish you good luck

i appreciate you trying to help

Did you Enable Studio Access to API Services ?

image
yes

well in a strange turn of events i figured it out