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