InvokeServer() makes my script stop, any help?

Heres the script:

local de = true
local Camera = workspace.CurrentCamera
local players = game.Players:GetPlayers() -- getting players
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventstar = ReplicatedStorage:WaitForChild("start")
local remoteEventwerewaiting = ReplicatedStorage:WaitForChild("waiting")
local function wearewaiting(value)
	remoteEventwerewaiting:FireServer()
end
script.Parent.MouseButton1Click:Connect(function()
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local remoteEvent = ReplicatedStorage:WaitForChild("waiting")
	
	print("working up to here")

	print("2")
	local RemoteFunction = game.ReplicatedStorage:WaitForChild("requestnew")
	print("3")
	local PassedValue = RemoteFunction:InvokeServer() 
	print("4")
	local remoteFunctionrn = ReplicatedStorage:WaitForChild("requestvalue")
	print("1")
	
	if de == true then
		print("able to click")
		if #players >=3 then
			print("enough ppl")
			
			if PassedValue then
				if PassedValue == true then
					print("round is not")
					local requestval = remoteFunctionrn:InvokeServer()
					if requestval == true then
						print("server isnt new")
						remoteEvent:FireServer()
						print("hi")
						wearewaiting()
						print("yay")
					else
						remoteEvent:FireServer()
						script.Parent.Text = "Loading"
						de = false
						wait(1)
						local plr = game.Players.LocalPlayer
						local character = plr.Character or plr.Character:Wait()
						Camera.CameraSubject = character.Humanoid
						for i = 1, 0, -.02 do
							script.Parent.Parent.Parent.darkness.BackgroundTransparency = i
							wait()
						end
						script.Parent.Parent.Parent.darkness.BackgroundTransparency = 0
						local children =script.Parent.Parent.Parent.mainrun:GetChildren()
						for i = 1, #children do
							children[i].Visible = false
						end
						wait(.5)
						Camera.CameraType = Enum.CameraType.Custom
						script.Parent.Parent.Parent.dead.Visible = true
						script.Parent.Parent.Parent.dead.LocalScript.Disabled = true
						script.Parent.Parent.Parent.dead.LocalScript.Disabled = false
						script.Parent.Parent.Visible = false
						wait(.5)
						for i = 0, 1, .02 do
							script.Parent.Parent.Parent.darkness.BackgroundTransparency = i
							wait()
						end
						script.Parent.Parent.Parent.darkness.BackgroundTransparency = 1
						script.Disabled = true
						wait(10)
						de = true	
						script.Parent.Text = "Play"
					end
				end	
			else
				script.Parent.Parent.Parent.noppl.Visible = true
			end	
		else 	

		end	
	end
			
end)
	
remoteEventwerewaiting.OnClientEvent:Connect(wearewaiting)

Line 19 or

local PassedValue = RemoteFunction:InvokeServer()

stops the script, no errors. Don’t know if 21 or

local remoteFunctionrn = ReplicatedStorage:WaitForChild(“requestvalue”)

also stops the script, but i haven’t gotten there.

I made sure that the right remote function is firing, server has a print, and it prints, i can provide the server script if you want but i don’t think that it is important
I have posted a simular situation before, right here

1 Like

Did you ever return a value? Remote functions must return a value or they will infinitely yield:

2 Likes

heres the server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteFunction = ReplicatedStorage:WaitForChild("requestvalue")
local remoteFunctionrt = ReplicatedStorage:WaitForChild("requestnew")
local remoteEventopt = ReplicatedStorage:WaitForChild("sendopt")
local remoteEventwait = ReplicatedStorage:WaitForChild("waitinglol")
local remoteEventweare = ReplicatedStorage:WaitForChild("waiting")


-- Create a new part and return it

local function createPart(player)
	local roundval = game.ServerScriptService.isround.Value
	return roundval
end

--local valuelol = game.ServerScriptService.new.Value
local function returnvals(player)
	local ExampleVal = script.Parent.isround.Value
	print(player.Name, ExampleVal)
	return ExampleVal
end

remoteEventopt.OnServerEvent:Connect(function(player)
	print("hi")
	if  player:GetAttribute("Opted") == true then
		player:SetAttribute("Opted", false)
		print("false")
	else
		player:SetAttribute("Opted", true)
		print("true")
	end
end)

local function plrwaiting(player)
	if  player:GetAttribute("playing") == true then
		player:SetAttribute("playing", false)
	else
		player:SetAttribute("playing", true)
	end
end

local function waitingbefore(player)
	for _, player in ipairs(game.Players:GetPlayers()) do
		if player:GetAttribute("playing") == true then
			script.waiitng.Value = script.waiitng.Value + 1
			local value = script.waiitng.Value
			remoteEventwait:FireAllClients(value)
			
end	
	end	
		end
local function wearewaiting(player)
	waitingbefore()
end


-- Bind the "createPart()" function to the remote function's "OnServerInvoke" callback
remoteFunction.OnServerInvoke = createPart
remoteFunctionrt.OnServerInvoke = returnvals
remoteEventwait.OnServerEvent:Connect(plrwaiting)
remoteEventweare.OnServerEvent:Connect(waitingbefore)

in short, yes i did use return
the important ones are createPart and returnvals

1 Like

i fixed it, the serverscript was hanging on an other remotevent that didn’t exist. i wish the serverscript through up an error but 2 weeks later (i counted) i got it fixed.

please if you have the same problem do these steps:
are you calling the right one?
is the server listening for the right one?
is the server hanging on an instance that doesnt exist? (use print(“hello”) over and over again in your script to find out where the error is)

i feel so dumb