What do you want to achieve? I have made a Datastore script in a new Flat terrain which I plan to use in one of my group games. I would like so people in my group game can see how active they are.
What is the issue? Include screenshots / videos if possible!
In my group game I already have a leaderboard script that will get the players Group Id and will assign that onto the leaderboard but I also am Trying to put My Datastore script that has a leaderstats value for minutes so when players join it should display both their rank from the group and how many minutes they currently have.
Leaderboard script for Group
local Players = game:GetService("Players") local groupId = (GroupId) Players.PlayerAdded:Connect(function(Player) local Leaderstats = Instance.new("Folder", Player) Leaderstats.Name = "leaderstats" local RankText = Instance.new("StringValue", Leaderstats) RankText.Name = "Rank" local Rank = Player:GetRoleInGroup(groupId) RankText.Value = Rank end)
local myDataStore = DataStoreService:GetDataStore("myDataStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Time = Instance.new("IntValue") Time.Name = "Time" Time.Parent = leaderstats local playerUserId = "Player_"..player.UserId -- Load Data local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(playerUserId) end) if success then Time.Value = data -- Set our data equal to the current Time end end) game.Players.PlayerRemoving:Connect(function(player) local playerUserId = "Player_"..player.UserId local data = player.leaderstats.Time.Value local success, errormessage = pcall(function() myDataStore:SetAsync(playerUserId, data) end) if success then print("Data sucessfully saved!") else print("There was an error!") warn(errormessage) end end)
Timer Script (This is a seperate script I made however I probably could have just added it elsewhere.)
while true do wait(60) player.leaderstats.Time.Value = player.leaderstats.Time.Value + 1 end end game.Players.PlayerAdded:connect(addTime)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I had to watch a 30 minute tutorial of how to save with Datastores etc I’m just in the process of learning how I can combine both my Datastore script + leaderboard group rank script to my group game.