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

How to solve RemoteFunction callback error in my random GUI giver script?

So i've been working on a game where a player is randomyl assigned a GUI whenever they fire a RemoteEvent. I changed this RemoteEvent to RemoteFunction because I wanted to be able to save the data of whatever GUI they are assigned. Simple enough. I just don't understand how to change the script for it being a RemoteFunction rather than event.

`` game.ReplicatedStorage.RemoteFunction4.OnServerInvoke(function(player)

local Item1 = game.Lighting.ScreenGui1

local Item2 = game.Lighting.ScreenGui2

local Items = {Item1, Item2}

local SpawnItem = Items[math.random(1,2)]

SpawnItem:clone().Parent = player.PlayerGui

end) ``

I keep getting the error: OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available  - 

1 answer

Right. First of all: USE CODE BLOCK. They come in these things ~~~~. Secondly, How a remote function works is that it is a FUNCTION. Functions can either do 2 things: perform operations, or return things. Here's how you should properly use OnServerInvoke.

game.ReplicatedStorage.RemoteFunction4.OnServerInvoke = function(player) --Replace the name with something that relates to the RemoteFunction. It'll be better, trust me.
	local Item1 = game.Lighting.ScreenGui1
	local Item2 = game.Lighting.ScreenGui2 --Not sure why you'd use lighting, use ReplicatedStorage.
	local Items = {Item1, Item2}
	SpawnItem:Clone().Parent = player.PlayerGui --clone() is deprecated.

	return true --Remote functions should be used to RETURN stuff. If you're not using it, then use a remote EVENT.
end

Here's some optimisation tips for you: You don't really need to use the server to manipulate the GUI. You can use a local script.

2 comments

0

Okay so, I put return true into my server and it still returns a callback error.

0

Return true is an example. Forgot to mention it.

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