Would this script cause too much lag?

Hello,
Recently I made a part that once touched will fire a Remote Event to the Client to make a GUI visible. If multiple players were to stand within the part for a long time (causing the Remote Event to rapidly fire) would lag become a serious issue?

For context, here is the script in question:

game.Workspace.TestPart.Touched:Connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		game.ReplicatedStorage.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
	end
end)

Thank your for any input. :+1:

you should look into debouncing

A simple instance would be is to just use a debounce to prevent the RemoteEvent from firing multiple times

Better yet, you could account for every individual player that touched the Part by using a table & checking if that specific player already touched the Part or not

local TouchedPlayers = {}
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local function Touched(Hit)
    local PlayerCheck = game.Players:GetPlayerFromCharacter(Hit.Parent)

    if PlayerCheck and not table.find(TouchedPlayers, PlayerCheck) then
        table.insert(TouchedPlayers, PlayerCheck)

        RemoteEvent:FireClient(PlayerCheck)
    end
end

workspace.TestPart.Touched:Connect(Touched)
1 Like