RemoteFunction yielding infinitely

I am working on a script that adds a function to all parts tagged “DeathRegion” that stops the camera script for 2 seconds then resumes functioning as normal, the problem is that the remotefunction i use just yields infinitely for no reason

local cs = game:GetService("CollectionService")
wait(3)
local Parts = cs:GetTagged("DeathRegion")

local functions = {}
local db = false
local function PseudoDeath(Otherpa)
	if db == false then
		db = true
		print("start")
		if game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent) then
			print("yes")
			local player = game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent)
			print("waiting")
			local Camera = game.ReplicatedStorage.GetCameraScript:InvokeClient(player)
			print("Done")
			Camera.Disabled = true
			print(Camera.Disabled)
			wait(2)
			Camera.Disabled = false
		elseif Otherpa.Anchored == false then
			wait(2)
			Otherpa:Destroy()
		end
		db = false
	end
end

for i , v in pairs(Parts) do
	v.Touched:Connect(PseudoDeath)
end

The remote functon btw:

script.Parent.OnClientInvoke = function() 
	return game.Players.LocalPlayer.PlayerScripts.Cmera 
end

This yields no error but it never prints “Done”

“game.Players.LocalPlayer.PlayerScripts.Cmera”?

Yes, If i have “Camera” or “camera” in the script’s name all default camera scripts

but is the name “Cmera”? you wrote “Cmera” in the script

also where’s the local script located? is it player scripts?

Yes :shallow_pan_of_food: :shallow_pan_of_food:

well, if you do have the player instance, why not do this?

local cs = game:GetService("CollectionService")
wait(3)
local Parts = cs:GetTagged("DeathRegion")

local functions = {}
local db = false
local function PseudoDeath(Otherpa)
	if db == false then
		db = true
		print("start")
		if game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent) then
			print("yes")
			local player = game:GetService("Players"):GetPlayerFromCharacter(Otherpa.Parent)
			print("waiting")
			local Camera = player.PlayerScripts.Cmera
			print("Done")
			Camera.Disabled = true
			print(Camera.Disabled)
			wait(2)
			Camera.Disabled = false
		elseif Otherpa.Anchored == false then
			wait(2)
			Otherpa:Destroy()
		end
		db = false
	end
end

for i , v in pairs(Parts) do
	v.Touched:Connect(PseudoDeath)
end

it’s a server script :shallow_pan_of_food:

epico.

where’s the remove function located?
also if it is a server script it wont find the camera, make it so the client script make the camera.Disabled true

The remote function is in replicatedstorage…
bruh i just realised I placed the script in the remote function instead of in replicatedfirst…

There are a few things wrong with this, first of all, you shouldn’t be using InvokeClient at all. Secondly, there is zero need to be doing this on the server. You’re also giving the client access to disable any script within their sight which is a terrible idea.

You should convert this to a LocalScript, and instead of using a RemoteFunction to get the camera script, just access it as normal while also adding checks to make sure only the LocalPlayer fires the Touched

1 Like

he’s not using a remote event, the client wouldnt disable anything

the remote function’s just returning the instance of the camera and the server’s disabling that when you’re touching the part.

exploiters wouldn’t be able to abuse anything with it

They can literally return any random script and due to this line with no checks in place Camera.Disabled = true they are able to disable anything

2 Likes

and make it local player only would just make exploiters able to abuse it, dude

also touched do not work for clients :slight_smile:

1 Like

That is entirely not true in any way shape or form please don’t spread misinformation :pensive:

The function does not seem to run anymore.
Oop nevermind my bad

“entirely not true”

tell me how you would make touched works for clients
im interested in that, cuz i just made 2 parts with the same script but one’s local script and the another one’s a script

note: only the script works, plase tell me how you’d make it work :slight_smile:

LocalScripts don’t run in the workspace did you establish the connection in playerscripts or replicatedfirst?
Yup tested it localscript is compatible with touch

maybe i didnt and i was just talking about the problem with touched in local scripts and that it doesnt work, the “BossSpax” solution wouldn’t work and that is it

lets keep the topic otherwise someone may flag us for breaking the rules

did your script worked? you said “oop nevermind my bad”

1 Like

Yeah it works now, the camera stops when the player touches the death region and starts again when they respawn