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

How can I use data stores correctly?

local DataStore = game:GetService("DataStoreService"):GetDataStore("mnaj22 level")


game.Players.PlayerAdded:connect(function(player)
	wait()
	
	Level = player.PlayerGui.ScreenGui.Value
	
	local key = "player-" ..player.userId
	
	local savedValues = DataStore:GetAsync(key)
	
	if savedValues then
		Level.value = savedValues(1)
	else
		local valuesToSave = (Level)
		DataStore:SetAsync(key, valuesToSave)
	end
end)

1 comment

0

17:16:27.671 - Workspace.Script:14: attempt to call local 'savedValues' (a number value) 17:16:27.681 - Stack Begin 17:16:27.682 - Script 'Workspace.Script', Line 14 17:16:27.683 - Stack End

2 answers

I'm not well-versed with data stores as yet, so I know I'm not the most qualified to answer this question -- but no one else is doing so. From looking at it (and checking the wiki a bit), it doesn't look as if your problem is in using the storage itself, but that you're setting your 'Level.value' to 'savedValues(1)' rather than just 'savedValues'. Not sure if I'm just misreading it.

1 comment

0

Yes, the parenthesis indicate he's trying to call a function from a number, that would break the script each time. He'll need to remove the (1).

local DataStore = game:GetService("DataStoreService"):GetDataStore("mnaj22 level")


game.Players.PlayerAdded:connect(function(player)
    wait()

    Level = player.PlayerGui.ScreenGui.Value

    local key = "player-" ..player.userId

    local savedValues = DataStore:GetAsync(key)

    if savedValues then
        Level.Value = savedValues[1]
    else
        local valuesToSave = Level
        DataStore:SetAsync(key, valuesToSave)
    end
end)

Few syntax mistakes. When you want to access a member of a table, use square brackets [] not parentheses ().

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