Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I wrap a RemoteFunction with a pcall?[SOLVED]

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 "="

2 answers

✓ Accepted answer

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!

1 comment

0

You can change success and message to be whatever you like.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.