I have a datastore in a "normal" script inside ServerScriptService. The datastore clones a stats folder inside ReplicatedStorage if a player joins, there aren't any errors. Why does it not save?
dss = game:GetService("DataStoreService")
ds = dss:GetDataStore("Gast")
game.Players.PlayerAdded:Connect(function(plr)
local stats1 = game.ReplicatedStorage:FindFirstChild("Stats")
local stats = stats1:Clone()
local gdata1 = game.ReplicatedStorage:FindFirstChild("GuiData")
local gdata = gdata1:Clone()
if stats then
stats.Parent = plr
if gdata then gdata.Parent = plr
end
key = plr.UserId
stats = plr.Stats
gdata = plr.GuiData
local saves = {stats.Gems.Value,stats.Coins.Value,gdata.Greeting.Value,stats.Damage.Value,stats.Speed.Value,stats.Health.Value}
local data = ds:GetAsync(key,saves)
if data then
print("Data loaded for User "..plr.UserId.."!")
stats.Gems.Value = data[1]
stats.Coins.Value = data[2]
gdata.Greeting.Value = data[3]
stats.Damage.Value = data[4]
stats.Speed.Value = data[5]
stats.Health.Value = data[6]
else
print("No Data for "..plr.UserId.."! Setting to default.")
stats.Coins.Value = 0
stats.Gems.Value = 0
gdata.Greeting.Value = true
stats.Damage.Value = 0
stats.Speed.Value = 0
stats.Health.Value = 0
end
end
pcall(function()
game.Players.PlayerRemoving:Connect(function(plr)
key = plr.UserId
local stats = plr.Stats
local gdata = plr.GuiData
local saves = {stats.Gems.Value,stats.Coins.Value,gdata.Greeting.Value, stats.Damage.Value,stats.Speed.Value,stats.Health.Value}
ds:SetAsync(key,saves)
print("User "..plr.UserId.." left the game. Saved Data for User "..plr.UserId..".")
end)
end)
game:BindToClose(function()
local players = game.Players:GetPlayers()
for i, player in pairs(players) do
player:Kick("Sorry, but the game is shutting down :(")
wait(5)
end
end)
end)

8 comments
try to change the name of the datastore
Why would I do that?
I don't see anything wrong with the script. Have you published your game and turned on api services?
yes
ok
didn't work
Are you running these tests in roblox studio? Sometimes roblox studio is not reliable for api services. Copy the link to your place/game and put it in your browser and see if it works
i already tried that