Grow Script lagging game

  1. What do you want to achieve? I want to make a game where you must survive a nuke in the default “Suburban” Roblox place.

  2. What is the issue? When the nuke is growing, it lags the game to the point where it is unplayable.

Video not loading, I can’t show :frowning:

  1. What solutions have you tried so far? I’ve tried using multiple different constraints such as the hinge and weld, but those lag the game, and weld doesn’t work properly with another script. I cannot have the nuke anchored as it uses a .Touched() event to work. I’ve also tried using BodyVelocity and BodyPosition, but those don’t work and they are deprecated.

Here’s my grow script.

local waittime = .001

while true do
	script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1)
	
	wait(waittime)
	waittime = waittime + .0001
	if waittime >= .1 then
		script.Parent:Destroy()
	end
end

Thank you!

It was giving me an error when putting the video, I’ll post it later for anyone willing to help me.

You could use the TweenService to make it grow. Also while true do loops are very laggy.

I think the next best thing would be to set the waittime a bit higher

You could also do a repeat until and then destroy()

Sadly, it still continued to lag. Hopefully I can figure this out!

Or you could use my solution, like this:

local waittime = .001

repeat
    script.Parent.Size = script.Parent.Size + Vector3.new(1,1,1)


    wait(waittime)
    waittime = waittime + .0001
until waittime >= .1
script.Parent:Destroy()

wait() can’t wait under .03 seconds, use task.wait() start at .16 (can’t go lower) use a while task.wait() loop

Can I see the code you used for the tween?

Sure.

local TweenService = game:GetService("TweenService")

local part = script.Parent
part.Size = Vector3.new(2, 2, 2)

local goal = {}
goal.Size = Vector3.new(512, 512, 512)

local tweenInfo = TweenInfo.new(100)

local tween = TweenService:Create(part, tweenInfo, goal)

tween:Play()

:smiley:

Probably not your issue but I strongly recommend you use task.wait() over wait()

Documentation on Task

I don’t know why that would lag at all, it shouldn’t.

I’m not a great scripter but what about task.wait(5)

the real issue here is the inherent cost of growing a part for whatever reason this operation is always laggy regardless of tween it must have something to do with how the engine calculates physics and the math/data im unsure tbh with you

to solve this issue I actually started using a file mesh inside a part and growing the file meshes scale you can also use a special mesh and select the shape you desire as a neat workaround this caused no lag for my server but to be double cautious I also made the client do it as added bonus that’s a separate can of worms but using tween to grow a part to large sizes is a guaranteed way to watch the server ping tank im unsure why but have experienced this problem for years

for dmg if your adding a .touched on top of a large growing part oh my goodness the lag from all the checks every time it touches something causes immense lag at large scales its better to grow a mesh scale not a meshpart sadly it suffers the same issues then use a magnitude check against all players to see if they are in the blast range this is easy enough example

if (player.Character.HumanoidRootPart.Position - nuke.Position).Magnitude < CurrentBlastradius then
player.Character.Humanoid.Health = 0
end