Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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?

0
Kenetec or whoever, please add some sort of Output button, similar to the SyntaxHighlighter, but for ROBLOX Output. adark 5487 — 10y

Locked by User#2

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
3
Answered by
Unclear 1776 Moderation Voter
10 years ago

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
0
Well that's annoying. :/ Hope ROBLOX changes that eventually. adark 5487 — 10y
0
Just tested it again, yep that fixed it. Thanks very much. adark 5487 — 10y
Ad