Hello! I'm currently making a game that requires leaderstats, (Trolls, Gems, Rebirths) and I am attempting to find a way to save these. I have tried watching some tutorials/youtube videos, yet none of them work.
Here's my leaderstats script:
game.Players.PlayerAdded:Connect(function(Player) if not Player:FindFirstChild("leaderstats") then local Folder = Instance.new("Folder" ,Player) Folder.Name = "leaderstats" end local Folder = Player:WaitForChild("leaderstats" ,5) local Value1 = Instance.new("IntValue",Folder) local Value2 = Instance.new("IntValue",Folder) local Value3 = Instance.new("IntValue",Folder) Value3.Name = "Trolls" Value1.Name = "Gems" Value2.Name = "Rebirths" end)
Any help or advice would be heavily appreciated!
Thanks
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")--Duplicate this and change name to rebirths 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)--Duplicate this and change name to rebirths gems.Name = "Gems"--Duplicate this and change name to rebirths local playerId = "Player_"..player.UserId local Trolldata local Gemsdata--Duplicate this and change name to rebirths local success, errormessage = pcall(function() Trolldata = Troll:GetAsync(playerId) Gemsdata = Gems:GetAsync(playerId)--Duplicate this and change name to rebirths end) if success then Troll.Value = Trolldata Gems.Value = Gemsdata--Duplicate this and change name to rebirths 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--Duplicate this and change name to rebirths local success, errormessage = pcall(function() Troll:SetAsync(playerId, Trolldata) Gems:SetAsync(playerId, Gemsdata)--Duplicate this and change name to rebirths 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")--Duplicate this and change name to rebirths 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)--Duplicate this and change name to rebirths gems.Name = "Gems"--Duplicate this and change name to rebirths local Rebirth = Instance.new("IntValue", leaderstats) Rebirth.Name = "Rebirth" local playerId = "Player_"..player.UserId local Trolldata local Gemsdata--Duplicate this and change name to rebirths local Rebirthdata local success, errormessage = pcall(function() Trolldata = Troll:GetAsync(playerId) Gemsdata = Gems:GetAsync(playerId)--Duplicate this and change name to rebirths Rebirthdata = Rebirth:GetAsync(playerId) end) if success then Troll.Value = Trolldata Gems.Value = Gemsdata--Duplicate this and change name to rebirths 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--Duplicate this and change name to rebirths local Rebirthdata = player.leaderstats.Rebirth.Value local success, errormessage = pcall(function() Troll:SetAsync(playerId, Trolldata) Gems:SetAsync(playerId, Gemsdata)--Duplicate this and change name to rebirths Rebirth:SetAsync(playerId, Rebirthdata) end) if success then print("Saved") else print("There was an error") warn(errormessage) end end)
Doesn't seem to work. It has red lines under every time it says TrollData, GemsData and RebirthsData (the new one I made for rebirths). I don't know why. An answer would be appreciated