Here is the script where I created my DataStore:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")
local service = game:GetService("MarketplaceService")
--[ LOCALS ]--
local VIPGamepassId = 27520453 -- VIP GAMEPASS ID
--[ FUNCTIONS ]--
game.Players.PlayerAdded:Connect(function(Player)
--[{ LEADERSTATS }]--
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Minutes = Instance.new("IntValue")
Minutes.Name = "Dakika" -- changing name here (points, levels, time, etc.)
Minutes.Value = 0 -- default value
Minutes.Parent = Player
--[{ DATA STORE }]--
local Data = DataStore:GetAsync(Player.UserId) -- Get Data
if type(Data) ~= "table" then
Data = nil
end
if Data then
Minutes.Value = Data.Minutes
end
local incrementValue = 1 -- value when adding points
if (service:UserOwnsGamePassAsync(Player.UserId, VIPGamepassId)) then -- 3x gamepass
incrementValue = 1
end
--[{ TIME GIVERS }]--
coroutine.resume(coroutine.create(function() -- gives 1 point every minute
while true do
wait(60) -- every minute
Minutes.Value = Minutes.Value + incrementValue -- adds points based off of the incrementValue
end
end))
end)
game.Players.PlayerRemoving:Connect(function(Player) -- save function here
--[{ DATA STORE SAVING }]--
DataStore:SetAsync(Player.UserId, { -- gets data
Minutes = Player.Dakika.Value,
})
end)
And the script that Roblox gave me:
local ServerStorage = game:GetService("ServerStorage")
local DataStoreService = game:GetService("DataStoreService")
local removePlayerDataEvent = ServerStorage:WaitForChild("RemovePlayerData")
-- Reference to player data store (replace "PlayerData" with the name of your data store)
local playerData = DataStoreService:GetDataStore("TimeStats")
local function onRemovePlayerDataEvent(userID)
-- Pattern for data store player key, for instance "Player_2522156542"
local dataStoreKey = "Player_" .. userID
local success, err = pcall(function()
return playerData:RemoveAsync(dataStoreKey)
end)
if success then
warn("Removed player data for user ID '" .. userID .. "'")
else
warn(err)
end
end
removePlayerDataEvent.Event:Connect(onRemovePlayerDataEvent)
What should I do? Are the lines correct?