i'm trying to learn about data store and have copied this script exactly the way it is from the youtube video I'm watching. enable studio access to api servers is on. after I change the value of Cash when I'm testing in the server nothing happens. no errors either
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
--Player Joins
game.Players.PlayerAdded:Connect(function(player)
--Gives Player Stats
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
end
end)
-- Save Data
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 Saved")
else
print("error")
warn(errormessage)
end
end)

1 comment
The first end goes below game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value).