user2255700
user2255700

Reputation: 113

Roblox - Trying to get InvokeClient Remote Function Working

In my server script called MainGameScript I have this code block:

local myRemoteFunction = Instance.new("RemoteFunction")
myRemoteFunction.Parent = game.Workspace
myRemoteFunction.Name = "GetBuildInfo"

game.Players.PlayerAdded:connect(function(player)
    print("[MainGameScript] added player") 

    for i,v in pairs(Regions) do
        if (v.Value == 0) then
            Regions[i].Value = player.UserId
            break
        end
    end    

    local success, result = pcall(function() return myRemoteFunction:InvokeClient(player) end)
    if success then
       print(result)
    else
        print("Error calling RemoteFunction GetBuildInfo")
    end

end)

I have a LocalScript in game.Workspace called LocalBuildScript which contains this:

function game.workspace.GetBuildInfo.OnClientInvoke()
    print("[GetBuildInfo] will send back local build info")
    return "this will be returned to the server caller script"
end

The GetBuildInfo function is never called. I have added some debug print lines to the calling function and the process seems to die at the point where it uses pcall... This is almost verbatim the Remote Function Client Invoke example from the Roblox Wiki, no idea why it is not working and am hoping somebody here has some experience using InvokeClient scripts.

Thanks, Andy

Upvotes: 0

Views: 1441

Answers (1)

Patrick Bell
Patrick Bell

Reputation: 769

The reason it isn't running is because LocalScripts being referenced by RemoteFunctions are expected to be inside of the Player instance somewhere in it. I'm fairly certain this is the case, as I've implemented a similar test system, but I held my LocalScript inside of the Player instance.

Upvotes: 2

Related Questions