Data stores just not working

I have been having a problem that I can’t fix were my data stores just won’t save. I looked at the documentation and they should be working.

local DSS = game:GetService("DataStoreService")
local PlrWeaponStore = DSS:GetDataStore("PlayerWeapon")
local Players = game:GetService("Players")
local Key = 822352643

Players.PlayerAdded:Connect(function(player)
	local Success, CurrentWeaponID = pcall(function()
		PlrWeaponStore:GetAsync(player.UserId)
	end)
	local WeaponID = Instance.new("NumberValue")
	WeaponID.Name = "WeaponID"
	WeaponID.Parent = player
	print(CurrentWeaponID)
	if CurrentWeaponID == nil then
		WeaponID.Value = 0
	else
		WeaponID.Value = CurrentWeaponID
	end
end)

Players.PlayerRemoving:Connect(function(player)
	local Success, Error = pcall(function()
		print(player.WeaponID.Value)
		PlrWeaponStore:SetAsync(player.UserId, player.WeaponID.Value)
	end)
	if not Success then
		warn(Error)
	end
end)

Here is my code.

Add in a bindtoclose() function.

2 Likes

I followed that and it still didn’t work and I got the warning “DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 822352643” in the output.

Add a return in your first pcall function. As of right now, CurrentWeaponID will always be nil, as you are not returning anything in you pcall function.

You know when you feel very very very dumb. That’s me right now

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