Here is a simply datastore system I did the first 2 for you. For practise try doing the 3rd.
Old Answer
Sorry I made some mistypes this should work now I tested it btw
Script:
local DSS = game:GetService("DataStoreService")
local Troll = DSS:GetDataStore("TrollData")
local Gems= DSS:GetDataStore("GemsData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Troll = Instance.new("IntValue", leaderstats)
Troll.Name = "Troll"
local gems = Instance.new("IntValue", leaderstats)
gems.Name = "Gems"
local playerId = "Player_"..player.UserId
local Trolldata
local Gemsdata
local success, errormessage = pcall(function()
Trolldata = Troll:GetAsync(playerId)
Gemsdata = Gems:GetAsync(playerId)
end)
if success then
Troll.Value = Trolldata
Gems.Value = Gemsdata
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerId = "Player_"..player.UserId
local Trolldata = player.leaderstats.Troll.Value
local Gemsdata = player.leaderstats.Gems.Value
local success, errormessage = pcall(function()
Troll:SetAsync(playerId, Trolldata)
Gems:SetAsync(playerId, Gemsdata)
end)
if success then
print("Saved")
else
print("There was an error")
warn(errormessage)
end
end)
Hope this helps!!
Updated Script
local DSS = game:GetService("DataStoreService")
local Troll = DSS:GetDataStore("TrollData")
local Gems= DSS:GetDataStore("GemsData")
local Rebirth = DSS:GetDataStore("RebirthData")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Troll = Instance.new("IntValue", leaderstats)
Troll.Name = "Troll"
local gems = Instance.new("IntValue", leaderstats)
gems.Name = "Gems"
local Rebirth = Instance.new("IntValue", leaderstats)
Rebirth.Name = "Rebirth"
local playerId = "Player_"..player.UserId
local Trolldata
local Gemsdata
local Rebirthdata
local success, errormessage = pcall(function()
Trolldata = Troll:GetAsync(playerId)
Gemsdata = Gems:GetAsync(playerId)
Rebirthdata = Rebirth:GetAsync(playerId)
end)
if success then
Troll.Value = Trolldata
Gems.Value = Gemsdata
Rebirth.Value = Rebirthdata
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerId = "Player_"..player.UserId
local Trolldata = player.leaderstats.Troll.Value
local Gemsdata = player.leaderstats.Gems.Value
local Rebirthdata = player.leaderstats.Rebirth.Value
local success, errormessage = pcall(function()
Troll:SetAsync(playerId, Trolldata)
Gems:SetAsync(playerId, Gemsdata)
Rebirth:SetAsync(playerId, Rebirthdata)
end)
if success then
print("Saved")
else
print("There was an error")
warn(errormessage)
end
end)
3 comments
https://devforum.roblox.com/t/datastores-beginners-to-advanced/1275421
I updated my answer it should work now
turn on API services in game setting under security