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

How do I work RemoteFunctions?

Asked by 5 years ago

Im unsure on how I would make i print what is what just so I can get the basics.

local Script in GUI

script.Parent.MouseButton1Click:Connect(function()
    local Crack = game.ReplicatedStorage.Money.Add.Code:InvokeServer()
    if Crack == "1" then
        print("Crack is 1")
    elseif Crack == "2" then
        print("Crack is 2")
    elseif Crack == "3" then
        print("Crack is 3")
    elseif Crack == "4" then
        print("Crack is 4")
    elseif Crack == "5" then
        print("Crack is 5")
    elseif Crack == "6" then
        print("Crack is 6")
    end
end)

ServerScript In ServerScriptService

game.ReplicatedStorage.Money.Add.Code.OnServerInvoke(ReturnValue)
function ReturnValue()
    local Value = math.random(1,6)
    print(Value)
    return Value
end

Nothing Prints or returns. I already read the wiki but still don't understand how to do it. How can I make this work so I can further understand it?

1 answer

Log in to vote
0
Answered by
yyyyyy09 246 Moderation Voter
5 years ago

So Remote Functions work differently from Event's, you cant put a function in the OnServerInvoke() scrictly because it, itself is already a function, and in this case, in your code "ReturnValue" is a passed variable.

instead you would want:


local remoteFunction = game.ReplicatedStorage.Money.Add.Code function remoteFunction.OnServerInvoke() local Value = math.random(1,6) print(Value) return Value end
1
Your explaination might be a bit confusing. You could just say that OnServerInvoke is a callback, unlike OnServerEvent which is an event Amiaa16 3227 — 5y
0
Still isn't working I somewhat understand it more but it won't print the value on the other side of the script Sergiomontani10 236 — 5y
0
other side being the Local Script side? yyyyyy09 246 — 5y
0
Yeah Sergiomontani10 236 — 5y
Ad

Answer this question