Script causing fps to drop to 12

Im have this script that checks how many players are in a part (capture zone) and their team, now when only one player is in the server it doesnt lag at all, but as soon as another player joined the fps for the player inside the zone dropes to 20 and when the other player is in the zone aswell it drops to 12 for both.
I have no idea why this is the cas so any help is welcome.

local Players = game:GetService('Players')
local Part = script.Parent

local PlayersTouchingPart = {}

Part.Touched:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	if Player and not table.find(PlayersTouchingPart ,Player.Name) then --Check if player exists and if the player is already in the table
		table.insert(PlayersTouchingPart, Player.Name)
		if tostring(Player.Team) == "Team Red" then
			script.Parent.RedTeam.Value += 1
			print(Player)
			print(script.Parent.RedTeam.Value)
		end
	end
end)

Part.TouchEnded:Connect(function(hit)
	local Player = Players:GetPlayerFromCharacter(hit.Parent)
	if Player and table.find(PlayersTouchingPart ,Player.Name) then -- Check if the player is in the table
		table.remove(PlayersTouchingPart, table.find(PlayersTouchingPart, Player.Name))
		if tostring(Player.Team) == "Team Red" then
			script.Parent.RedTeam.Value -= 1
			print(Player)
			print(script.Parent.RedTeam.Value)
		end
	end
end)

4 Likes

I copied the code into a new baseplate, personally didn’t have any framerate drops for 1 player, or 2 players or 3.
Perhaps there is something else in the game causing the drop in frame rate?
Also, do you normally have frame rate issues in either Roblox or Studio?

1 Like

“Perhaps there is something else in the game causing the drop in frame rate?”
i dont think so as the game ran perfectly fine before i added this script
and I never really have fps drops in roblox or studio

Try copying the capture zones as well as the script into a fresh baseplate, and test to see if there is any frame rate issues there for you. If there isn’t, then I reckon that some other script in your game is interacting with the new capture zones you’ve added in a way which causes the frame rate to drop.

ok so i dont have the fps drops in a baseplate but nothing interacts with the capture zone in the main game (confirmed that with the script search)

Could you post some pictures of the hierarchy as well as other scripts?

Edit: By any chance are you printing to the console a lot? This causes lag in studio.

I’ve a script which work the same way.
It should not drop your fps, check other scripts (maybe you didn’t disabled something)

Using Print() surprisingly uses a ton of resources, so try removing those.

1 Like

i could try it out to see if it works better

i already checked, it only prints once so it doent print 4000000 times

grafik
or do you mean smth else?

You could always use the microprofiler to find out what’s the source of your lag.

It shows all your script runtimes and the default ones provided by roblox aswell.

make a test studio and if there is fps drop over there send me copy of it

as i already said, it works fine on a baseplate, but i dont want to send a whole copy of the game

1 Like

send me in private chat (ofc only if you want to trust me. my discrd is: the_killerhood if you want to add me and ill sharescreen)

since im not really familiar with the profiler heres a screenshot

we can do it over discord once im done with smth else

I may have ran into a similar issue recently, I’m not sure if it’s related, but what is your values for this:

i have the same values as you do in that screenshot
grafik

if you can’t find a solution I’d recommend using ZonePlus

2 Likes