I have a datastore, it does print the load portion, but it doesnt print the save portion so I assume it doesnt work. Why is this? I cant seem to find a solution for this. The script also doesn't print any errors whatsoever.
local datastore = game:GetService("DataStoreService")
local mydatastore = datastore:GetDataStore("mydatastore")
game.Players.PlayerAdded:Connect(function(player)
-- DEFINING VALUES --
local stam = Instance.new("IntValue")
stam.Value = 100
stam.Name = "Stamina"
stam.Parent = player
local maxstam = Instance.new("IntValue")
maxstam.Value = 100
maxstam.Name = "MaxStamina"
maxstam.Parent = player
local coins = Instance.new("IntValue")
coins.Value = 0
coins.Name = "coins"
coins.Parent = player
local fs = Instance.new("StringValue")
fs.Value = "Punch"
fs.Name = "FS"
fs.Parent = player
local f = Instance.new("StringValue")
f.Value = "Dirt Dirt Fruit"
f.Name = "F"
f.Parent = player
local w = Instance.new("StringValue")
w.Value = "Punch"
w.Name = "W"
w.Parent = player
-----------------------------------------------------
------------- DATA RETRIEVING ------------------
local data
pcall(function()
data = mydatastore:GetAsync(player.UserId)
end)
if data == nil then print("No data")
else print("Data found")
coins.Value = data[4]
fs.Value = data[1]
f.Value = data[2]
w.Value = data[3]
end
-----------------------------------------------------
end)
game.Players.PlayerRemoving:Connect(function(player)
------------- DATA SAVING -----------------------
local success, errormessage = pcall(function()
mydatastore:SetAsync(player.UserId,{player.FS.Value,player.F.Value,player.W.Value,player.coins.Value})
end)
if success then
print("Data saved for "..player.Name)
else
print("Data not saved for "..player.Name)
warn(errormessage)
end
-----------------------------------------------------
end)

1 comment
Thanks, I'll try this.