I have no clue on how to wrap this with a pcall
xpFunction.OnServerInvoke=function(plr) local key = 'Player-'..plr.userId -- Checks if player has data that can be sent if xpDataStore:GetAsync(key) then return xpDataStore:GetAsync(key) else -- sets the xp to 0 if plr is new xpDataStore:SetAsync(key,(0)) end end
I have tried this
pcall(xpFunction.OnServerInvoke=function(plr) local key = 'Player-'..plr.userId -- Checks if player has data that can be sent if xpDataStore:GetAsync(key) then return xpDataStore:GetAsync(key) else -- sets the xp to 0 if plr is new xpDataStore:SetAsync(key,(0)) end end)
but there is an error with the "="
Try this:
local success, message = pcall(function() xpFunction.OnServerInvoke = function(plr) -- code in here end end)
Hope this helps and have a great day scripting!
It's fairy simple. Do it like this:
xpFunction.OnServerInvoke = function(plr) local s, ret = pcall(function() local key = 'Player-'..plr.UserId --use uppercase U in UserId if xpDataStore:GetAsync(key) then return xpDataStore:GetAsync(key) else xpDataStore:SetAsync(key, 0) end end) return ret end