Hello. I’m having a bit of an issue with a tornado I made. Whenever the destroy part touches a big group of parts, the game lags a lot, and yes I’ve tried looking up things for it but they all suggested things that didn’t work [such as adding a debounce didn’t work, and it also just made it impossible for the tornado to destroy anything].
Here’s a video showcasing it. No, it’s not the script that destroys things, it still lags even when it doesn’t have the ability to destroy. FPS is displayed in the bottom right. https://gyazo.com/d52301abf915dc7b6089551795788333
local tor = script.Parent
local debounce = false
local attackrange = nil
scale=script.Parent.Parent.Parent.Parent.Scale
function suck(val)
-- enssential stuff
local str = Instance.new("StringValue")
str.Name="StruckByTor"
str.Parent=val
game.Debris:AddItem(str,15)
local chance=math.random(1,8-script.Parent.Parent.Parent.Parent.Scale.Value)
if chance==1 then
val.Anchored=true
local ss=script.Parent.SuckingScript:Clone()
ss.Parent=val
ss.Disabled=false
val.Parent=script.Parent.Parent.Debri
end
end
script.Parent.Touched:Connect(function(hit)
if hit:IsA("BasePart") and not hit:FindFirstChild("StruckByTor") then
local sstring=tonumber(hit.Name)
if sstring~=nil and sstring<=scale.Value then
suck(hit)
end
end
end)```
Thank you for helping!
Unfortunately, that’s pretty much the nature of .Touched events, it’s just not very feasible with high part counts. If you really want to keep using it, I would advise having to group parts together and having the primary part’s CanTouch to true, while disabled on the rest of the other children, chunks essentially.
However that’s pretty impractical when building, unless you can make yourself a module to automatically group close parts together, set the primary part to the closest center part, etc.
One quick thing that may help performance is to set the CanTouch property to false once parts are being sucked up by the tornado, assuming you have no need for touch events afterwards.
Otherwise, I would advise you to use a Heartbeat connected event with Region3’s, preferably with a debounce (don’t run the code if the previous step’s hasn’t finished yet).
Ah apologies, like i said i just did a quick read and didnt see anything about what it was or what it was suppose to do, i just know a .Touched without a wait is a disaster of an issue all the times
I didnt comment for someone to prove my advice wrong lol, just let him try it out and if it didnt work then oh well. Stop trying to disprove other peoples advice like your trying to prove your knowledge or something