Remote Function not invoking (SOLVED)

  1. What do you want to achieve? Person level ups once completed level

  2. What is the issue? A remote function doesn’t work

  3. What solutions have you tried so far? I have but print statements showing that the code doesn’t go after on server invoke.

First script - runs after completed level (local)

game.ReplicatedStorage.Completed:InvokeServer()

Second script (normal)

game.ReplicatedStorage.Completed.OnServerInvoke = function()
		print("Works")
		if Level < 3 then
			levelval.Value = 3
			print("RUN3")
		end
	end
5 Likes

When the client invoked a RemoteFunction, the local script which invoked the RemoteFunction will yield until the server returns something. In your server script code, you didn’t return anything, so you should store the invocation of the remote event into a variable which will contain the returned value from the server.

Does this print statement gets fired?

1 Like

The print statement does not fire.

Then most likely your local script is erroring. It would be better if you show us more parts of the local script codes.

1 Like

This is what happens when the player succeeds.

	if keeprunning == false then
			script.Parent.Parent.Parent.Time.Text = "✅"
			script.Parent.Parent.Parent.Time.Text = timeleft
			repeat
				wait()
				camera.CameraType = Enum.CameraType.Scriptable
			until camera.CameraType == Enum.CameraType.Scriptable

			camera.CFrame = focus.CFrame
			print("Won")
			game.ReplicatedStorage.Completed:InvokeServer()
			game.Workspace.Correct:Play()
			script.Parent.Parent.Parent.TextLabel.Visible = false
			script.Parent.Parent.Parent.Time.Visible = false
			script.Parent.Parent.Parent.Parent.NextLevelScreen.Frame.Visible = true
			break
		end
1 Like

Does this print statement works if the player succeeds?

1 Like

No, the statement does not print.

1 Like

Then most likely this if statement evaluated to false which doesn’t execute the code you posted previously. Please make sure this if statement is indeed evaluating to true to execute the code.

2 Likes

Oh wait sorry that was an error “won” does print.

1 Like

Then I have possibly no clue what’s wrong with your code. Either you try to use print statements to confirm that the invocation is working OR your remote function needs to be replaced.

1 Like

Ok thank you! Sorry for troubling you! I will review the code more!

2 Likes

What are Level and levelval referring to?

Don’t forget when the client invokes the server the player instance belonging to that client is automatically passed to the server as an argument.

game.ReplicatedStorage.Completed.OnServerInvoke = function(player)

This isn’t required but typically when the client invokes/fires the server you do something with that particular client.

1 Like

Thank you for replying! The level and levelval refer to a datatstore in which the game saves your level!

1 Like

Any chance you have multiple scripts/functions trying to handle the same .OnServerInvoke? RemoteFunctions can only have one function assigned to each callback (OnServer/OnClientInvoke)

8 Likes

Wow! Thank you so much! I found another script looking for invoked! Because one script is for money and the other for level. So when you finish the level you get that level and you get money! Sorry that was a bad mistake!

4 Likes