This crashes my client always

Paste this in a localscript and put it in StarterGui and run a single client server

Players = game.Players
Player = Players.LocalPlayer


_G.localData=_G.localData or {}
_G.localData.playerNameToUserIdTab = {}
_G.localData.userIdToPlayerNameTab = {}


function pcallGetNameFromUserIdAsync(userId)
local errorOrSuccessful, pcallReturn = pcall(function() 
return Players:GetNameFromUserIdAsync(userId)  
end)
return pcallReturn
end


function getPlayerNameFromUserId(userId)
if _G.localData.playerNameToUserIdTab[userId] == nil then --if you never got the player's name, get it
local getPlayerName = pcallGetNameFromUserIdAsync(userId) --get player name
_G.localData.playerNameToUserIdTab[userId] = getPlayerName --put it in global table for next time
end
return _G.localData.playerNameToUserIdTab[userId] --return player name
end


getPlayerNameFromUserId(261)

I believe it is the _G messing with it.

DEL TEMP.png

Super weird. Out of curiosity, can you try adding this line of code to the FIRST line of your getPlayerNameFromUserId function?:

userId = tostring(userId)

I’m curious to see if that fixes this issue, based on the text in parentheses in the error message about keys needing to be strings. I’m not home right now so can’t test this for myself, sorry.

genius. Still strange that it must crash me otherwise.

Glad that worked! But I’m still really curious as to why that error is showing up. Maybe someone else here will know. It sounds like an internal error within Lua itself, so I really doubt your code is to blame.

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