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

[RESOLVED] GetAsync returning RemoteFunction with "Request rejected" instead of math.huge?

LocalScript. buyButton is a SurfaceGui button. Both descend from PlayerGui.

buyButton.MouseButton1Click:connect(function()
	if tonumber(func:InvokeServer({"GetToolLastPurchased", toolsToRentOrBuy[index][1]})) > 60*60*24--[[24 hours Also on Script line 71]] then --Line 59
		--snip
	else
		--Already purchased recently
	end
end)

Script, descendant of Workspace.

local func = Instance.new("RemoteFunction", Game:GetService("ReplicatedStorage"))
func.Name = "inspiredMessage" --To avoid potential name conflicts.
function func.OnServerInvoke(player, args)
	if args[1] == "GetToolLastPurchased" then
		local testVar = store:GetAsync(player.Name)
		if not testVar or testVar == "Request rejected" then
			return math.huge
		elseif not testVar[args[2]] then
			return math.huge
		else
			return Tick() - testVar[args[2]]
		end
	--snip
	end
end

Output (From Client, not Server):

22:54:48.521 - Request rejected

22:54:48.522 - Script 'Players.Player1.PlayerGui.LocalScript', Line 59

22:54:48.523 - stack end

22:54:48.524 - Players.Player1.PlayerGui.LocalScript:59: attempt to compare number with nil

22:54:48.525 - Script 'Players.Player1.PlayerGui.LocalScript', Line 59

22:54:48.526 - stack end

"Request rejected" is a string returned by GetAsync when trying to access a DataStore from a test Server, which I am.

My problem is that "Request rejected" is getting sent to the Client, not math.huge which I am expecting. The LocalScript isn't breaking, but I can't figure out how to make this work as I expect it to.

Any help?

1 comment

0

Kenetec or whoever, please add some sort of Output button, similar to the SyntaxHighlighter, but for ROBLOX Output.

1 answer

✓ Accepted answer

Well, judging from

22:54:48.524 - Players.Player1.PlayerGui.LocalScript:59: attempt to compare number with nil

I'm guessing the issue is that OnServerInvoke is returning nil. I suspect what this means is that your key hasn't been defined yet. If this is true, try replacing line 5 in the Script with...

local testVar = store:GetAsync(player.Name) or "Request rejected"

Turns out, GetAsync does not return nil when there is no value associated with the key. It just returns absolutely nothing (try verifying that by attempting to print the type of an undefined key...). This is pretty annoying, but using or we can remedy that by providing a fallback value for us to use in case there's no value.

Here's what it would look like with that fix...

local func = Instance.new("RemoteFunction", Game:GetService("ReplicatedStorage"))
func.Name = "inspiredMessage" --To avoid potential name conflicts.
function func.OnServerInvoke(player, args)
    if args[1] == "GetToolLastPurchased" then
        local testVar = store:GetAsync(player.Name) or "Request rejected"
        if type(testVar) ~= "table" then -- Assuming testVar should be a table.
            return math.huge
        elseif not testVar[args[2]] then
            return math.huge
        else
            return Tick() - testVar[args[2]]
        end
    --snip
    end
end

2 comments

0

Well that's annoying. :/ Hope ROBLOX changes that eventually.

0

Just tested it again, yep that fixed it. Thanks very much.

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