Remote Function not working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want me remote function to work
  2. What is the issue? Include screenshots / videos if possible!
    It doesn’t fire the server, and the local side gets paused
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    uniqe problem
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--client
game.ReplicatedStorage.RemoteFunction:InvokeServer(1,"TutorialCompleted", false)
print("easdasdasdasdad")

result = game.ReplicatedStorage.RemoteFunction:InvokeServer(2,"TutorialCompleted")
print(result)
print("easdasdasdasdad")
--Server
game.ReplicatedStorage.RemoteFunction.OnServerInvoke:Connect(function(Player,Action,variable,Value)
	print(Action)

It just gets paused at the very first invoke, and the server side doesn’t print the action

--Server
game.ReplicatedStorage.RemoteFunction.OnServerInvoke:Connect(function(Player,Action,variable,Value)
	print(Action)

You’re not assigning the callback a variable, I think this should work

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player,Action,variable,Value)
      print(Action)
      return("Activated")
end

local ServerScriptService = game:GetService(“ServerScriptService”)
local PlayerDataModule = require(ServerScriptService.ModuleScripts.PlayerDataModule)
print(“eee”)
game.ReplicatedStorage.RemoteFunction.OnServerInvoke:Connect(function(Player,Action,variable,Value)
print(Action)

if Action == 1 then
	print("easedaseas")

	PlayerDataModule.setData(Player, variable, Value)

	return(0)
elseif Action == 2 then
	local Result
	Result = PlayerDataModule.getData(Player)
	Result.TutorialCompleted = Result.TutorialCompleted or {}
	return(Result)
end

end)

Are you allowing the client to send variables to set as the players data? Also what exactly do you need help with, I’ve tried adding the callback to your original script and it worked fine for me.

not working for me, and yes I am sending variables to set player data, client is in gui

First of all that’s a horrible way to do it as the client can send whatever it wants and you’re not even doing any checks on it, so say an exploiter could either send any value they want or send a value, which would result in an error preventing the data from saving and causing a data rollback.
Never trust the client.

Secondly, you don’t use RemoteFunctions the same as RemoteEvents, RemoteFunctions have a callback so you don’t write OnServerInvoke:Connect, but you assign the function a variable and then return what you want to be sent back to the client, such as here:

--CLIENT
result = game.ReplicatedStorage.RemoteFunction:InvokeServer(2,"TutorialCompleted")
print(result)


--SERVER
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player,Action,variable,Value)
	print(Action)
	return("Activated")
end


--EXPECTED OUTPUT
  21:45:56.752  2  -  Server - Script:2
  21:45:56.760  Activated  -  Client - LocalScript:2

this worked, but the values don’t get passed though, printing them doesn’t work

Please send me the server script so I can take a look. Also are you sure you want to use a RemoteFunction and not a RemoteEvent? They’re quite a bit more unsafe and for for what you’re doing, a RemoteEvent would work just fine I think.

local ServerScriptService = game:GetService(“ServerScriptService”)

local PlayerDataModule = require(ServerScriptService.ModuleScripts.PlayerDataModule)
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player,Action,variable,Value)

if Action == 1 then
	print(Action)
	print(variable)

	PlayerDataModule.setData(Player, variable, Value)

	return(0)
elseif Action == 2 then
	local Result
	Result = PlayerDataModule.getData(Player)

	return(Result.TutorialCompleted)
end

end

for some reason it recognises action as 1 but then prints it as nothing. Also setdata not firing

So I’m not sure what exact data module you’re using and I can’t exactly replicate what you have, but from what I’ve tested it works just fine with slight modifications:

CLIENT:

result = game.ReplicatedStorage.RemoteFunction:InvokeServer(2,"TutorialCompleted")
print(result)

SERVER:

local ServerStorage = game:GetService("ServerStorage")

local PlayerDataModule = require(ServerStorage.ModuleScripts.PlayerDataModule)
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player,Action,variable,Value)
	if Action == 1 then
		print(Action)
		print(variable)

		PlayerDataModule.setData(Player, variable, Value)

		return("Here is what the client will print as the result")
		
	elseif Action == 2 then
		local Result = PlayerDataModule.getData(Player) --made the module print "got data"

		return("Completed") -- Also the result
	end
end

EXPECTED OUTPUT:

 22:13:40.016  got data  -  Server - PlayerDataModule:4
  22:13:40.022  Completed  -  Client - LocalScript:2

It did everything I expected it to do, I’m not sure how you’re module works so I just made mine print statements to simulate it:

local module = {}

module.getData = function()
	print("got data")
end

module.setData = function()
	print("set data")
end

return module

Sorry if I’m not answering your question too well, but I’m not sure what you want to achieve with:
return(Result.TutorialCompleted)
If you need further help please go a bit more into detail on exactly what you want to behave how and why it’d not behaving the way you want it to, thanks.

1 Like