RemoteEvent problem

Hi all,
I want to make it so when a player enters a Region3, a gui will popup strictly for
that player and they can interact with it and such. I have it setup so that the
server script detects whenever a player enters the Region3. However, whenever the
server fires a remote event to the player, the client doesn’t receive it. I think it may have to
do with the variable “plyr,” but I’m unsure why.

Server script:

local repStorage = game:GetService("ReplicatedStorage")
local events = repStorage.Events


while true do
	wait(.5)
	for _, property in pairs(game.Workspace.Properties:GetChildren()) do
		local boundBox = property:FindFirstChild("boundary_box")
		local regionPart= boundBox
		local pos1 = regionPart.Position - (regionPart.Size / 2)
		local pos2 = regionPart.Position + (regionPart.Size / 2)
		local region = Region3.new(pos1, pos2)
		local partsInRegion = game.Workspace:FindPartsInRegion3(region, boundBox, 1000)
		
		--// Contesting Script
		
		local t = {}	
		for _, part in pairs(partsInRegion) do	
			local plyr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
			if plyr and not table.find(t, plyr) then
				table.insert(t, plyr)
				
				events.showGui:FireClient(plyr)
				
				if #t >= 2 then
					print(property.Name.." is contested!")
				end
			end
		end
	end
end

Local Script:

local repStorage = game:GetService("ReplicatedStorage")
local userInput = game:GetService("UserInputService")
local localPlyr = game:GetService("Players").LocalPlayer
local events = repStorage.Events

--// Gui Handler

local function testF()
	print("Receieved")
end

events.showGui.OnClientEvent:Connect(testF)

Any and all help is greatly appreciated

1 Like

make sure both for loops are not breaking early - use a variable to count the number of loops it does after seeing how many parts it needs to loop through. I had this same problem a little while ago.
e.g.

print(#partsInRegion) -- prints 10 for example
e = 0
for _, v in pairs(partsInRegion) do
     e = e + 1
end
print(e) -- should also print 10

if there are no errors, this could be the issue

Does this code error at all, because one error will result in that while true do loop breaking (I would suggest alternatively to rely on RBXScriptSignals to mitigate this), but adding prints throughout your code is a very handy debugging tool to ensure the code you want to run is actually running. For example; add a test print right below the table.insert(t, plyr) to ensure that your server code is actually attempting to fire the client, and if not, just keep tracing back the steps of the code until you determine where the issue is.