Why does this simple script lag so much?

This has been a problem all day, originally it was lagging the server like crazy so i made it client based, but now its lagging the client!

I dont think theres a memory leak, really i have no idea what it is

local rs = game:GetService('RunService')
local humanoidRootPart = script.Parent.HumanoidRootPart -- startercharacterscript
local player = game.Players.LocalPlayer
while wait(0.1) do

	local inafeild = false
	local currentfeild = player.Values.Feild.Value -- stringvalue
	local box = workspace[currentfeild..'Box'] -- hitbox for a feild, just a normal big part
	if table.find(workspace:GetPartBoundsInBox(box.CFrame, box.Size), humanoidRootPart) then
		inafeild = true
	end


	if player.Values.InFeild.Value ~= inafeild then
		game.ReplicatedStorage.events.FeildClientToServer:FireServer(inafeild)
	end

end

1 Like

as you can see, it lags every 0.1 seconds

This may be causing the issue, try using workspace:GetPartsInPart(box) or other alternative methods

Or another alternative is using zone+. It’s a really cool module. Search it up.

1 Like

this is a little bit better, but it still continues to noticeable lag every 0.1 seconds

There isn’t really any other way, try using what @SilentSuprion said (if it works mark him as the solution)

1 Like

how do i remove a zone? like remove it from memory

Maybe zone = nil. Did you try looking into the functions? Or try contacting the owner.

1 Like

couldnt figure it out, i dont think you can, i just remade how the script worked so it didnt make multiple

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.