This category should only be used for open discussions on Roblox development!
Please use #help-and-feedback:game-design-support if you need help implementing specific game features. ``` local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Cash.Value = data
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “Player_”…player.UserId
local data = player.leaderstats.Cash.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
else
print("There was an error!")
warn(errormessage)
end
end) ``` Theres no error, but its not saving either
I tried all of those things, and it still doesn’t work
My code is here
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“myDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
-- Load Data
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(playerUserId)
end)
if success then
Cash.Value = data
-- Set our data equal to the current Cash
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = “Player_”…player.UserId
local data = player.leaderstats.Cash.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
else
print("There was an error!")
warn(errormessage)
end
Nah, HTTP Requests aren’t linked to API requests from Roblox, in fact a lot of stuff you mess with HTTPService is limited to stuff outside roblox. You can’t even do a request from roblox to roblox. Unless you’re using a proxy, anyways, datastores are roblox services and they’re only accessible through roblox itself. Hmm…
You said the same on another post but ok :P
To the original poster:
Please format your code correctly. Don’t use the quotes icon to format it there’s one which is a </> icon. Use that instead. Its very hard to read it.
Make sure to check if you have data or no, it makes debugging easier.
if success then
if data then -- make sure to always check it inside the if success statement
warn("data found")
Cash.Value = data
else
warn("data not found")
end
else
warn("failed to load")
end