So I was watching a data store tutorial and copied off the scripts, but it isn’t working when I’m done the script, it doesn’t say anything wrong in the output and my api is on, but it just isn’t working, so can anyone figure out why my script isn’t working?
local DataStoreService = game:GetService(“DataStoreService”)
local Datastore = DataStoreService:GetDataStore(“Datastore”) – creates datat store
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder") -- make leaderstat
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 = Datastore:GetAsync(playerUserId)
end)
if success then
Cash.Value = data
-- set out data equal to 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()
Datastore:SetAsync(playerUserId, data)
end)
if success then
print("SUCCESS")
else
print("ERROR!")
warn(errormessage)
end
end)