RemoteFunction from Client to Server returning nil

Basically the Script invokes the client and then the player is supposed to click on one of 3 buttons. When a button is clicked or 10 seconds have passed, its supposed to return a certain value.
However, it doesnt do that and doesnt return anything. After 10 seconds it returns something, but its nil. The button works because it does everything before the return part of the code.
Ive even tried wrapping it in a pcall function. It says that its successful but the server still doesnt get the returned message.

(In the video, it flashes around because theres supposed to be dialog in the cutscene, but i skipped it for the sake of testing it)


ServerScript:

local plr = game.Players:GetChildren()[1]
local choice = game.ReplicatedStorage.MakeChoice:InvokeClient(plr)
print(choice)
if choice == "KillBall" then
	sounds["Dark Zone"]:Stop()
	changecam(game.Workspace.CamParts.BossfightOver.BossfightOverCam1)
	dialog("I'm sorry Ball Person...", "Player")
	dialog("Its time for you to go", "Player")
	deadballcut.PlayerClone.Gun.Handle.Attachment.Smoke:Emit(15)
	deadballcut.PlayerClone.Gun.Handle.Attachment.ParticleEmitter:Emit(7)
	deadballcut.PlayerClone.Gun.Handle.Attachment.ParticleEmitter:Emit(1)
	deadballcut.PlayerClone.Gun.Handle.Fire:Play()
	wait(0.3)
	changecam(game.Workspace.CamParts.BossfightOver.BossfightOverCam2)
	sounds.BallDeflect:Play()
	for i = 1,5 do
		ball.ShieldEffect.ParticleEmitter:Emit(1)
		wait(0.08)
	end
end
print("over")

LocalScript

game.ReplicatedStorage.MakeChoice.OnClientInvoke = function()
	local chosen = false

	local choicemenu = game.Players.LocalPlayer.PlayerGui.ScreenGui.ChoiceScreen
	choicemenu.Visible = true

	choicemenu.KillBall.MouseButton1Click:Connect(function()
		print("Kill")
		choicemenu.Visible = false
		return "KillBall"
	end)
	choicemenu.SpareBall.MouseButton1Click:Connect(function()
		choicemenu.Visible = false
		return "Spare"
	end)
	choicemenu.KillDod.MouseButton1Click:Connect(function()
		choicemenu.Visible = false
		return "KillDod"
	end)

	wait(10)
	if chosen == false then
		choicemenu.Visible = false
		return "slow"
	end
end

script.Parent.ScreenGui.ChoiceScreen.Visible = false

So. First, this is RemoteFunction from server to client, which is highly not recommended.
Other thing is, that RemoteFunctions are happening only once the client receives the invocation message. What your script does is when player receives this message, it will create mouse click connections and that’s all… After player clicks the choice, it will return a string into nowhere. In fact, the return is total nonsense.

So what you should do is to fix your RemoteFunction by calling it from client to server, and call it only when player clicks the choice in the choice menu.

If you wanna keep your code structure, send a RemoteEvent to the client, that the client must make a choice, when choice is selected, client will send a RemoteEvent to the server with the choice selected.

Hope you understand it all, if not, tell me, I’ll try to describe it better and provide you some documentation links to understand this stuff correctly. Remember, that sending RemoteFunction from server to client is highly not recommended, since client can somehow decide not to answer, and the thread on server is hanged forever. Also making connections inside the invocation doesn’t make sense, since the connection is only made, but the thread will not wait for the player to choose, because, it would hang the server thread until player answers. Read something about connections in Roblox, so you understand how it all works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.