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

Datastore attempts to index number with number and fails?

So when the datastore script tries to get the Cubes value from the Datastore, it gives me an error saying "ServerScriptService.Datastore:9: Attempted to index number with number" which I have no idea on how to fix.

Datastore script:

local datastore = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrid = "id_"..plr.UserId
	local save1 = plr.leaderstats.Cubes
	
	local GetSaved = datastore:GetAsync(plrid)
	if GetSaved then
		save1.Value = GetSaved[0]
	else
		local NumSave = {save1.Value}
		datastore:GetAsync(plrid,NumSave)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	datastore:SetAsync("id_"..plr.UserId,plr.leaderstats.Cubes.Value)
end)

Leaderstats script:

local Players = game:GetService("Players")

local function leaderboardSetup(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local cubesmade = Instance.new("IntValue")
	cubesmade.Name = "Cubes"
	cubesmade.Value = 0
	cubesmade.Parent = leaderstats
end

Players.PlayerAdded:Connect(leaderboardSetup)

2 answers

GetSaved[1] and local GetSaved = datastore:GetAsync("id_"..plrid)

4 comments

0

it works now, but it won't save. Every time I rejoin the cubes get set back to 0.

0

Leaderstats?

0

?

0

like i dont see you setting the value

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