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

Line 21: Attempt to index local 'savedvalue' (a number value)? [Needs resolving]

local datastore = game:GetService("DataStoreService"):GetDataStore("rP")
local serverstorage = game:GetService("ServerStorage")
game.Players.PlayerAdded:connect(function(plyr)
	local rp = Instance.new("IntValue")
	rp.Parent = serverstorage
	rp.Name = "rP-"..plyr.Name
	local key = "plyr"..plyr.userId
	local username = Instance.new("StringValue")
	username.Parent = serverstorage
	username.Name = plyr.Name
	username.Value = plyr.Name
	
	local userid = Instance.new("IntValue")
	userid.Parent = serverstorage
	userid.Name = plyr.Name.."-id"
	userid.Value = plyr.userId
	
	local savedvalue = datastore:GetAsync(key)
	
	if savedvalue then
		rp.Value = savedvalue[1]
		username.Value = savedvalue[2]
		userid.Value = savedvalue[3]
	else
		datastore:SetAsync(key, rp.Value, username.Value,userid.Value)
	end
end)

This is my code. I can't figure out why it cannot index savedvalue.

Any input?

1 answer

✓ Accepted answer

You seem to be saving a tuple, however, you are trying to access it like you would a table. I'll rewrite line 25 datastore:SetAsync(key, {rp.Value, username.Value, userid.Value})

2 comments

0

This doesn't fix it. I'm still getting the same error.

0

Oh wait, I think that this might be because sometimes DataStore will make the number be something like 10.0000000001. Since IntValues can't use decimals, try using math.floor() to round it down

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