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 work RemoteFunctions?

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

✓ Accepted answer

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

4 comments

1

Your explaination might be a bit confusing. You could just say that OnServerInvoke is a callback, unlike OnServerEvent which is an event

0

Still isn't working I somewhat understand it more but it won't print the value on the other side of the script

0

other side being the Local Script side?

0

Yeah

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