Need help with the scripts I created

  1. 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.

  2. 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)

Datastore script

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)
  1. 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.
1 Like

I don’t see a problem, does it warn you the error?

No When I put those scripts in ServerScriptservice it only displays my Rank but not how many minutes for some strange reason.

May you show your leaderboard? When you check if it was success, you didn’t check if there is a data.

I must have added the scripts incorrectly as now it shows up! :smiley: except the only error i get is Time is not a valid member of Folder.

1 Like

This has to be fixed if its still going on. This scared the heck out of me and I thought my account was stolen until i heard it was a bug.

6 Likes


I waited a minute to see if the time updated and it did not.

Where the scripts are.

My game has lost almost 50% of the players in the last hour and my group admin isn’t loading correctly. Servers might be breaking because it’s the weekend.

6 Likes

Can you point out in the script (adding a comment by doing --) where the error is coming from?

Now it does not display an error. for some reason however I cannot see my group rank anymore and instead it now decides to start counting the minutes.
Edit
It must be glitching or something cause i just retested it and now displays my Group rank again. Never mind here is the error.

1 Like

Can you show your new script? (Full script)

Edit: Maybe it was an error while trying to get your role in the group.

It means a child named “Time” doesn’t exist.

Assuming I just need to add player.leaderstats:WaitForChild(“Time”) ?

1 Like

you are running it twice so just do something to like loop the players or so and find them in players and add their timer by one