The player with user id is not present at the moment

hi, I’m currently facing a problem that’s currently slowing down my game.
When I opened the developer console inside my game I was greeted with a warning “the player with user id: (the id) is not present at the moment.”
It’s not just few warnings, it kept spamming it, about 100 warnings in one second.
I know which script this is coming from but I do not know how to fix it!!
I barely don’t know how to script and I just follow tutorials. please help.

Can you show us the script please? Without it we can barely help you.

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore(“TotalTime”)

local Players = game:GetService(“Players”)

local sessionData = {}

local AlwaysTrue = true

local function savePlayerData(playerUserId, plr)

playerData:SetAsync(playerUserId, plr.leaderstats.Time.Value)

print("Everything is fine, data saved.")

end

local function saveOnExit(plr)

local playerUserId = "Player_" .. plr.UserId

savePlayerData(playerUserId, plr)

end

local function onPlayerAdded(plr)

local playerUserId = "Player_" .. plr.UserId

local leaderstats = Instance.new("Folder")

leaderstats.Parent = plr

leaderstats.Name = 'leaderstats'

local timee = Instance.new("IntValue")

timee.Parent = leaderstats

timee.Name = 'Time'

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("TotalTime")

local playerUserId = "Player_" .. plr.UserId

local sessionData = {}

local data = playerData:GetAsync(playerUserId)

timee.Value = data

repeat

	wait(60)

	local newTime = timee.Value + 1

	timee.Value = newTime

until AlwaysTrue == false

end

Players.PlayerRemoving:Connect(saveOnExit)

Players.PlayerAdded:Connect(onPlayerAdded)

AAGH I’m not good at using this site, they’re all one script for some reason its in parts

Shouldn’t it be data[1], because GetAsync is table and you need to get the index from the table.

When I do that it gives a syntax error

The problem is I don’t know on which line its erroring. Can you please try to give me the line on which the error appearing and also try to wrap it to pcall.

local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore(“TotalTime”)

local Players = game:GetService(“Players”)

local sessionData = {}

local AlwaysTrue = true

local function savePlayerData(playerUserId, plr)

playerData:SetAsync(playerUserId, plr.leaderstats.Time.Value)

print("Everything is fine, data saved.")
end

local function saveOnExit(plr)

local playerUserId = "Player_" .. plr.UserId

savePlayerData(playerUserId, plr)
end

local function onPlayerAdded(plr)
local suc, err = pcall(function() 
local playerUserId = "Player_" .. plr.UserId

local leaderstats = Instance.new("Folder")

leaderstats.Parent = plr

leaderstats.Name = 'leaderstats'

local timee = Instance.new("IntValue")

timee.Parent = leaderstats

timee.Name = 'Time'

local DataStoreService = game:GetService("DataStoreService")

local playerData = DataStoreService:GetDataStore("TotalTime")

local playerUserId = "Player_" .. plr.UserId

local sessionData = {}

local data = playerData:GetAsync(playerUserId)

timee.Value = data

repeat

	wait(60)

	local newTime = timee.Value + 1

	timee.Value = newTime

until AlwaysTrue == false
end) 

if err then
print(err) 
end
end

Players.PlayerRemoving:Connect(saveOnExit)

Players.PlayerAdded:Connect(onPlayerAdded)
1 Like

it looks like it’s fixed now. thank you for your help <3

1 Like

Glad that you fixed it I looked up to devforum and this issue appeared only once back in 2018. :smiley:

1 Like

aagh it started doing it again. :cry: I’ve also been suspecting this leaderboard script I have but when I deleted it, it still kept doing it.

Alright try to pass the

"Player_" .. plr.UserId

like this to SaveData functions and not in local variable (playeruserid).

didn’t work. just broke the script, or i did it wrong

Can you show me the edited script please.

It’s a warning. That wouldn’t do anything.

1 Like

I already erased it but it was all over the place. now that I think about it, it was quite obvious it wasn’t going to work. I’m pretty bad when it comes to understanding written text so it could have been that I did something wrong

Yeah ur right wrapping it to pcall is not good solution but overall it should be wrapped in pcall.

You should only wrap unsafe methods (GetAsync) that you can’t stop from erroring in pcall, not your entire code.

2 Likes

Your script is consisting of lots of extra variables and unnecessary functions. Here I revised your script and deleted them. I have never met this error before. You may try this but I’m not sure if the same error exists.

local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("TotalTime")

local function saveOnExit(plr)

    local playerUserId = "Player_" .. plr.UserId

    local data
    local suc, err = pcall(function()
	    data = playerData:SetAsync(playerUserId, plr.leaderstats.Time.Value)
    end)

    if not suc then
	    print(err)
    end

end

local function onPlayerAdded(plr)

    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = plr
    leaderstats.Name = 'leaderstats'

    local timee = Instance.new("IntValue")
    timee.Parent = leaderstats
    timee.Name = 'Time'

    local playerUserId = "Player_" .. plr.UserId

    local data
    local suc, err = pcall(function()
	    data = playerData:GetAsync(playerUserId)
    end)

    if suc then
	    timee.Value = data
    else
	    print(err)
    end


    while true do

	    wait(60)

	    timee.Value += 1
	
    end
end

game:GetService("Players").PlayerRemoving:Connect(saveOnExit)

game:GetService("Players").PlayerAdded:Connect(onPlayerAdded)

thank you!!! it usually takes about 10-20 minutes for the warning to show up so I will reply if it appears again.

yea it didn’t work I still get the warning messages.