Help with DataStoreService

Is the DataStoreService down? Or am I missing something?

local ds = game:GetService("DataStoreService")
local gd = ds:GetDataStore("GunData")


game.Players.PlayerAdded:Connect(function(plr)
	local gdata = Instance.new("StringValue")
	gdata.Name = "GunData"
	gdata.Parent = plr
		
	local data		
	local success, failure pcall(function()
		data = gd:GetAsync(plr.UserId.."-guns")
	end)
		
	if success then
		gdata.Value = data
	else
		plr:Kick("Datastore is NOT working")
	end
end)


game.Players.PlayerRemoving:Connect(function(plr)
	local success, failure pcall(function()
		gd:SetAsync(plr.UserId.."-guns", plr.GunData.Value)
	end)

	if success then
		print("Data Saved")
	else
		print("Data not saved (so sad)")
	end
end)

Is this a leaderstats datastore or is it just some stats?

try to add an = between your failure and pcall in your playerremoving event

1 Like

Yo thank you so much! I haven’t used pcalls at all so I didn’t know. That also fixed all the unexplainable red underlines on :

if success then
--blah blah blah
end
``