Why doesn't this data store script work? I am not getting any errors!
EXTREMELY GRATEFUL FOR HELP Here is the script:
-- Define variables
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
-- You should put your data store as a separate variable then the service one
local DataStore = DataStoreService:GetDataStore("NameHere")
-- Loads the data back to the player
game.Players.PlayerAdded:Connect(function(player)
-- Creates the stats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue")
points.Name = "Points"
points.Parent = leaderstats
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
local Key = "player-"..player.UserId -- key
local success, message = pcall(function()
SavedStats = DataStore:GetAsync(Key)
end)
-- Gives the player the data if they have data else create a datastore for them
if SavedStats then
points.Value = SavedStats[1]
coins.Value = SavedStats[2]
else
local Values = {
points.Value;
coins.Value
}
local success, message = pcall(function()
DataStore:SetAsync(Key, Values)
end)
end
Key = "player-"..player.UserId
valuesToSave = {
player.leaderstats.Points.Value;
player.leaderstats.Coins.Value}
local succes, message pcall(function() -- Stops errors
DataStore:SetAsync(Key, valuesToSave)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, message = pcall(function()
DataStore:SetAsync(Key, valuesToSave)
end)
end)
end)

1 comment
you won't learn by copy pasting code