I have a DataStore script that saves Bool Values
I tested it and it works
Then i put the script in an other place and it didnt worked anymore why?
This is the script :
local DSS = game:GetService(“DataStoreService”)
local datastore = DSS:GetDataStore(“WeaponSkinSave”, “Players”)
function generateDataKey(player)
local ret = “uid_” … player.userId
return ret
end
function generateDataTable(player)
local dataTable = {
Points = player:WaitForChild(“PlayerGui”):WaitForChild(“WeaponSkins”).Rainbow.Owned.Value
}
return dataTable
end
function saveDataForPlayer(player)
local key = generateDataKey(player)
local data = generateDataTable(player)
datastore:SetAsync(key, data)
end
function inputDataToPlayer(player, data)
player:WaitForChild(“PlayerGui”):WaitForChild(“WeaponSkins”).Rainbow.Owned.Value = data.Points
end
function loadDataForPlayer(player)
local key = generateDataKey(player)
local data = datastore:GetAsync(key)
inputDataToPlayer(player, data)
end
ServerScriptService.DataStore:24: attempt to index local ‘data’ (a nil value) 21:04:44.100 - Stack Begin 21:04:44.100 - Script ‘ServerScriptService.DataStore’, Line 24 - global inputDataToPlayer 21:04:44.101 - Script ‘ServerScriptService.DataStore’, Line 30 - global loadDataForPlayer 21:04:44.101 - Script ‘ServerScriptService.DataStore’, Line 34 21:04:44.101 - Stack End
For other place> Does this mean that you have a game with places? If not, DataStore cannot be cross-compatible between different games, you’d have to have your own web hosting to store data, or store them on a spreadsheet, which is a bit more complex than just DS…
It’s a bit hard to read when you copy-paste it into an article.
Usually when you need help with code, you should upload it or format it correctly to make it easy to read.
Try uploading the file of the script for everybody.
local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("WeaponSkinSave", "Players")
function generateDataKey(player)
local ret = "uid_" .. player.userId
return ret
end
function generateDataTable(player)
local dataTable = {
Points = player:WaitForChild("PlayerGui"):WaitForChild("WeaponSkins").Rainbow.Owned.Value
}
return dataTable
end
function saveDataForPlayer(player)
local key = generateDataKey(player)
local data = generateDataTable(player)
datastore:SetAsync(key,data)
end
function inputDataToPlayer(player, data)
player:WaitForChild("PlayerGui"):WaitForChild("WeaponSkins").Rainbow.Owned.Value = data.Points
end
function loadDataForPlayer(player)
local key = generateDataKey(player)
local data = datastore:GetAsync(key)
inputDataToPlayer(player, data)
end
game.Players.PlayerAdded:connect(function(player)
loadDataForPlayer(player)
player:WaitForChild("PlayerGui"):WaitForChild("WeaponSkins").Rainbow.Owned.Changed:connect(function()
saveDataForPlayer(player)
end)
end)
game.Players.PlayerRemoving:connect(saveDataForPlayer)
Found the issue. At line 30 you try to call function inputDataToPlayer. If you print it, I bet it would return nil for the data variable. That means you are storing the data incorrectly (or so it seems). It’s a bit weird that it worked somewhere else. Keep in mind that you can only save integers, so make sure that is what you are doing.
No, this information is false. You can save any valid Lua primitive type except functions, threads and userdata. That’s nil, strings, numbers, booleans and tables.
OP’s issue is that their code assumes that all code returns truthy values and doesn’t handle any errors of any kind, especially if no data is returned from a GetAsync call. This is something that can be fixed through a general code skim and confirming what is being saved.
If what you mean is,
You created a DS script, for a specific place, which save player stats let’s say, and you want the same script to work to a different place to load the stats to another game, based on the game you have the DS script(Basically Cross Compatible) You will need to web host a data store. You can’t do that just by placing the same script inside another game you made.
Maybe try keeping the DataStore script in different places in the same universe, not different games.
Because places in a game are all connected, they can share the same DataStore, because starter places (games) are not connected, they cannot share the same DataStore.
CFrames and Instances are userdata. You can verify this by using the Lua Global type on an object. The Roblox Global typeof will return Roblox and Lua primitive datatypes.