In this video, we're gonna learn how to save player data using Datastores :D
Subscribe for part 3 of the simulator series!
--------------------------------------------------------------------------------------------------------------------------
🎮Roblox Profile: https://www.roblox.com/users/34873063...
🧊Roblox Group:
https://www.roblox.com/groups/1723045...
👾Discord Server: / discord
Music Credits:
Acid Trumpet by Kevin MacLeod | https://incompetech.com/
Music promoted by https://www.chosic.com/free-music/all/
Creative Commons: By Attribution 3.0 License
http://creativecommons.org/licenses/b...
--------------------------------------------------- Scripts --------------------------------------------------------
Datastore Script:
local Players = game.Players
local DatastoreService = game:GetService("DataStoreService")
local Datastore = DatastoreService:GetDataStore("PointStore")
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Points = Instance.new("NumberValue")
Points.Name = "Points"
Points.Value = 0
Points.Parent = leaderstats
local PlayerData = Datastore:GetAsync(player.UserId)
Points.Value = PlayerData.Points
end)
Players.PlayerRemoving:Connect(function(player)
local success, errorMessage = pcall(function()
local data = {
Points = player.leaderstats.Points.Value
}
Datastore:SetAsync(player.UserId, data)
end)
if not success then
warn(errorMessage)
end
end)
Sell Part Script:
script.Parent.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
Player.leaderstats.Points.Value = 0
end
end)