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

Why won't this datastore script store data?

I'm not getting any errors from the script (I removed the pcalls to make sure) Can someone help me out?

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

game.Players.PlayerAdded:Connect(function(plr)
	local key = "id-"..plr.UserId
	local Stats = Instance.new("Folder",plr)
	local Lvl = Instance.new("IntValue",Stats)
	local Exp = Instance.new("IntValue",Stats)
	local Exc = Instance.new("IntValue",Stats)
	local Pts = Instance.new("IntValue",Stats)
	local Arm = Instance.new("IntValue",Stats)
	local Dmg = Instance.new("IntValue",Stats)
	local Rei = Instance.new("IntValue",Stats)
	Stats.Name = "Stats"
	Lvl.Name = "Lvl"
	Exp.Name = "Exp"
	Exc.Name = "Exc"
	Pts.Name = "Pts"
	Arm.Name = "Arm"
	Dmg.Name = "Dmg"
	Rei.Name = "Rei"
	local info = ds:GetAsync(key)
	pcall(function()
		Lvl.Value = info[1]
		Exp.Value = info[2]
		Exc.Value = info[3]
		Pts.Value = info[4]
		Arm.Value = info[5]
		Dmg.Value = info[6]
		Rei.Value = info[7]
		if Lvl.Value == 0 then
			Lvl.Value = 1
		end
		if Exc.Value == 0 then
			Exc.Value = Lvl.Value * 5
		end
		end)
	
	while Exp.Value >= Exc.Value do
		Lvl.Value = Lvl.Value + 1
		Exp.Value = Exp.Value - Exc.Value
		Exc.Value = Lvl.Value * 5
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local key = "id-"..plr.UserId
	local info = {}
	local Stats = plr:WaitForChild("Stats")
	local Lvl = Stats:WaitForChild("Lvl")
	local Exp = Stats:WaitForChild("Exp")
	local Exc = Stats:WaitForChild("Exc")
	local Pts = Stats:WaitForChild("Pts")
	local Arm = Stats:WaitForChild("Arm")
	local Dmg = Stats:WaitForChild("Dmg")
	local Rei = Stats:WaitForChild("Rei")
		table.insert(info,Lvl.Value)
		table.insert(info,Exp.Value)
		table.insert(info,Exc.Value)
		table.insert(info,Pts.Value)
		table.insert(info,Arm.Value)
		table.insert(info,Dmg.Value)
		table.insert(info,Rei.Value)
	ds:SetAsync(key,info)
end)

1 answer

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