A safe alternative for RemoteFunction?

Hi! I am making a “Level Completed” Gui and I need a RemoteFunction to fire the player from the server and wait until the player returns “Continue” or “Main menu”.
From what I know, firing RemoteFunctions from the server is really bad since an exploiter (the player we’re firing) could yield his script, which would then yield the server.
Is there a better and safe alternative?

If there isn’t, it’s probably okay since it’s a single player game, but lag on the client could yield the server too, right?

1 Like

RemoteEvent from server > client > server
classic.

Yeah, but I have to wait before the client sends the string to the server. That would yield the server too, I think.

You could check if the remote function doesn’t returned in x times.

Remote events don’t yield therefore if they try yield it would only yield on 1 thread.

But if I program it to yield like

--// Wait for the client to return the string
RemoteEvent.OnServerEvent:Wait()

It would yield.

Why would you want to design it to yield? Remote events are generally safer and better than remote functions as they don’t yield if you use them appropriately.

Yes, but why would you need to do that though.

I am making a “Level completed. Continue?” prompt that will prompt the player each time he completes a level.
As the server, I would have to wait before the player clicks one of two buttons - “Continue” or “Main menu”

You don’t need to wait if you have signals to listen to inputs. They won’t yield the script.

Okay, I’ll try listening for Button.MouseButton1Click from the server. Does that work?

That only works for the client. Fire a remote event from the client when they have inputted then the server will need safe checks.

Okay, but now I would have (again) to wait until a player clicks “continue” before proceeding to the next level.

Yeah and you don’t need to wait if you’re using events. Why do you need to wait?

1 Like

If I spawned the next level before the player even had the chance to click “Return to main menu”, the player would be pretty annoyed.

That’s why you spawn the next level if the event is active.

How and when are you spawning the next level?

I want to spawn the next level when the player clicks “Continue” and run my code to return to main menu when he clicks “Main menu”

Yes so when the player has activated a gui send the button he has clicked to the server. The server will validate if the button is real. Then decides if he wants to continue or go the main menu.

Oh I got it! Is this what you mean?

Event.OnServerEvent:Connect(function(_, continue)
    if continue then
        spawnLevel()
    else
        mainMenu()
    end
end)
1 Like