Ordered DataStore not working in-game

So i have a leaderboard in my game. In studio it works, but in-game it only works with my main account. When i change accounts it doesnt work for some weird reason.
Main account:


Tester account:

When the game starts i wait 10 second and then iterate through the ordered datastore and set the values on the leaderboard but the only thing that appears on the tester account is the template frame but the leaderboard is not showing. Why is this happening?

1 Like

Did you enable API Services in the game settings?

1 Like

Can you send output in server after play testing?

oooh ty i didnt know u could see output in game. Anyway the problem seems to be this:

	template.User.Text = Plrs:GetPlayerByUserId(entry.key).Name

when i set players to the ordered datastore i use userID so now im trying to get the player name from that userid but i get:
image

Why does it work on my main account but not with other accounts?

Can you provide the full script?

For the record, Players:GetPlayerByUserId(userId) accepts a number as an argument and returns a Player instance that corresponds to that user ID if they are in the game. You’re probably looking for

local userExists = true --whether this UserId was terminated or is invalid
userExists, template.User.Text = pcall(Plrs.GetNameFromUserIdAsync, Plrs, tonumber(entry.key))

if not userExists then
	-- etc.
end

but this is just my guess at first glance. At the very least, your error message means that the player with the given UserId wasn’t in the game.

If you also want the users’ display names, get all of them from your DataStore, then use UserService:GetUserInfosByUserIdsAsync().

ooh tysm yeah thats prolly why, didnt know it only worked if that player was in game

ill use :GetNameFromUserIdAsync() instead

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.