Hello!
So I was working on some datastore stuff, but when i use stat.Value etc etc it doesn’t work if this is enabled:
But it DOES work when it’s disabled, but then I CANNOT use datastores, any solution for this?
Hello!
So I was working on some datastore stuff, but when i use stat.Value etc etc it doesn’t work if this is enabled:
But it DOES work when it’s disabled, but then I CANNOT use datastores, any solution for this?
No errors whatsoever, i’m real confused.
What do you mean by ‘doesn’t work’? It doesn’t save? or doesn’t create?
Also, don’t use the parent argument for Instance.new
(if you care about performance)
local obj = Instance.new('Part')
obj.Parent = workspace
-- much faster on a roblox compiler scale
First of all. Just because you enabled data store doesn’t mean EVERYTHING is going to save. You must enable API Services and DataStoreService in order to save.
And just use
local wallet
Instead of stat I guess.
No like, saving is not the problem here mostly, it’s the stat.Value, i can show you the thing idk what’s wrong with it
DataStore:GetAsync
doesn’t use 2 arguments. It only takes the key because it returns what’s saved with it
DataStore:GetAsync("string_key") -- just the key, nothing else
So basically: DataStore:GetAsync(player.UserId…"-Lvl") for example
Yes, like that. If the data store has data it’ll return it, otherwise it’ll return nil, so make something to check that; so you don’t get errors that the script is attempting to set a nil value to an IntValue
Probably because the value of the wallet was something else before you changed it try using a datastore editor to change the values
I don’t know if i’m dumb but like this?
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("ApeGorillaDS1")
game.Players.PlayerAdded:Connect(function(player)
local leaderstat = player:WaitForChild("ValueStats")
local stat = Instance.new("IntValue",leaderstat)
stat.Name = "Wallet"
stat.Value = 1000
local success, errorm = pcall(function()
data = ds:GetAsync(player.UserId.."-stat")
end)
if success then
stat.Value = data
else
warn(errorm)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errorm = pcall(function()
ds:SetAsync(plr.UserId.."-stat", plr.ValueStats.Wallet.Value)
end)
if success then
else
warn(errorm)
end
end)
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("ApeGorillaDS1")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local stat = Instance.new("IntValue",leaderstats)
stat.Name = "Wallet"
stat.Parent = leaderstats
stat.Value = 1000
local success, errorm = pcall(function()
data = ds:GetAsync(player.UserId.."-stat")
end)
if success then
stat.Value = data
else
warn(errorm)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errorm = pcall(function()
ds:SetAsync(plr.UserId.."-stat", plr.ValueStats.Wallet.Value)
end)
if success then
else
warn(errorm)
end
end)
it already parents it here
Yes, but add this to the pcall
if success then
if data then -- this checks if the user has data to load
stat.Value = data
else
warn("no data to load")
end
I already tried that before, jus the same
Are you running it in studio? If so, run it in a live game because data stores don’t typically work in studio
When you retrieve the data from DataStore, it can be nil, so you can’t set stat.Value
to nil. That may prompt an error.
I’d suggestion adding an if check:
if data ~= nil then
stat.Value = data
end
Already did, also the parenting is not the problem, it’s just the value that doesn’t want to change
That’s weird, did you publish the game?
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("ApeGorillaDS1")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Wallet = Instance.new("NumberValue")
Wallet.Name = "Wallet"
Wallet.Parent = leaderstats
Wallet.Value = 1000
local key = player.UserId
local data
local success,msg = pcall(function()
data = ds:GetAsync(key)
end)
if data then
print("Data Loaded")
Wallet.Value = data.W
else
print("Error")
warn(msg)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = player.UserId
local data = {
W = player.leaderstats.Wallet.Value
}
local success,msg = pcall(function()
data = ds:SetAsync(key,data)
end)
if success then
print("DataSaved")
end
end)