Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm So Confused! My DataSaver Won't Work? It Doesn't Show Any Errors Either

I've been trying for the past 30 minutes to get this to work,

it doesn't show any error code or anything

it just doesn't save the data.

local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("KillsDataSaver")


game.Players.PlayerAdded:Connect(function(plr)
	
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr
	
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"	
	kills.Parent = stats
	
	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = stats
	
	local data 
	local success, errormessage = pcall(function()
		data = ds:GetAsync(plr.UserId.."-kills")
	end)
	
	if success then
		kills.Value = data
	else
		print("There Was A Data Error")
		warn(errormessage) 
	end
	plr.CharacterAdded:connect(function(char)
		
		local humanoid
		
		repeat
			humanoid = char:FindFirstChild("Humanoid")
			wait()
		until humanoid
		
		humanoid.Died:connect(function()
			
			deaths.Value = deaths.Value + 1
			
			local tag = humanoid:FindFirstChild("creator")
			
			if tag then
				
				local killer = tag.Value
				
				if killer then
					
					killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
				end
			end
		end)
	end)
	
end)

game.Players.PlayerRemoving:Connect(function(plr)
	
	
	local success, errormessage = pcall(function()
		ds:SetAsync(plr.UserId.."-kills",plr.leaderstats.Kills.Value)
	end)
	
	if success then
		print("Kills Saved!")
	else
		print("Data Saving Error")
		warn(errormessage)
	end
	
end)

1 comment

0

It Still Doesn't Work

1 answer

In the website, where you name your game tick the box saying, Enable Studio API services. To get to this menu click on your published game, click game settings or edit game or something like that.

1 comment

0

I have Api services enabled, it still won't work

This discussion is preserved as it was. New answers, comments, and votes are closed.