Problem with Testing Mode

I click on test, 2 Players and it kicks both players because it cannot load the datastore.

I click on test, 1 Player and it works fine.

The live game also works fine with multiple players.

It used to work, now it doesn’t.

CODE:

local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("Testing")

game.Players.PlayerAdded:Connect(function(player)
local success, value = pcall(dataStore.GetAsync, dataStore, player.UserId)
	if success == false then player:Kick("Data could not be loaded! Please rejoin.") return end

I don’t know if it will work but try adding this

local PlayerUserId = "Player_"..Player.UserId

[EDIT]
I have been corrected by the posts below.
Apologies. I have not commonly used pcall that way. Thanks for the information.

Thank you for correcting me.

Actually, what he has is correct. And is a more proper way to format your pcall.

3 Likes

In pcall, arguments are passed as other variables, function is formatted with [.] instead of [:]

3 Likes

When you playtest with only a single player it will use that players UserId. When you playtest with multiple players it gives them false userids in the form of -1, -2, -3 etc so that’s what is probably causing your issues.

1 Like

What do you see if you print value before kicking them?

I believe negative numbers are still valid keys. I may be wrong, but when concatenated in a string they still work. I believe they still work alone.

1 Like

adding onto what @ZombieCrunchUK said, you could use math.abs to get absolute number, so it can’t be negative

UserId = math.abs(Player.UserId)

They are valid keys, but there might be something that is preventing it from getting / saving.

A key is a key, a string, or a code that can be uused to get a specific set of items.

Wouldnt be a good idea, but because of the inactivity of the accounts, it would work? But I would recommend keeping it as a negative value, just to be sure.

Are you using the UserIds table when saving the data? Perhaps you should check there if it is a negative number too and if it is, then don’t use the userids table for that data. I understand that you are seeing the error when attempting to load the data, but I just want to confirm this as it will likely cause saving errors.

I am unsure as to why this would cause a retrieval error. Considering they are valid keys. Perhaps access to the data store service is being blocked for some reason.

I looked at the names of the players:

Test with 1 Player = Player1

Test with 2 Players = Player1, Player2

Printing the value

1 Player = nil
2 Players = 502: API Services rejected request with error. HTTP 403 (Forbidden) (x2)

Another odd thing.

After 2 Players fails I sometimes cannot save the file.

If get the following message:

Place upload endpoint not found.
Place Publish Error - HTTP 404 (Not Found):
-- and then. few hundreds lines of code starting with
<!DOCTYPE html>

I have to quit Studio and reload my file.

Is studio access to API services on? If not, that will be the problem.
It is unlikely, but otherwise, it could be blocked by an antivirus or something.

Either a problem with your anti-virus blocking it or a problem with your internet I’d say.
I don’t think the roblox API is down at the moment.

No sure anti virus is the answer.

Testing Mode with 1 Player works fine.

The error only occurs when there is more than 1 Player loaded by the Testing Mode.