Is it fine to use this server-side tween?

I have a nuke product in my game, tweens a ball + rocket on server I would usually tween it on the client but problem is that if a player joins late in the server they won’'t see the effects taking place.

Will it really affect performance that much? Here’s the nuke:

1 Like

Tweens aren’t “dangerous” to use on the server and it’s totally fine to use them like this. All you should watch out for is connecting to a signal of the tween and not disconnecting after the tween finished playing, this will cause a memory leak.

The only issue with server tweens is that they will heavily impact your network between server and client, but I can imagine this is fine-- though honestly you could just lerp the position on the server as a value, and everytime the server value changes, you could make the client read it and update accordingly.

I was thinking of doing this but I’m pretty sure that would be more impactful on performance or just more complicated rather than using tweens which are quite simple.

Here’s the code if you wanna take a look, I just destroy the tweens after their completed events have fired.

if not workspace:GetAttribute("NukeInProgress") then
				workspace:SetAttribute("NukeInProgress", true)
				Player.leaderstats[" Spent"].Value += 600
				for i = 0.5, 0, -0.001 do
					MainMusic.Volume = i
					task.wait(0.01)
				end
				for _, player in Players:GetPlayers() do
					player.PlayerGui.NukeGui.PurchasedText.Text =  Player.Name .. " Purchased A Nuke!"
					player.PlayerGui.NukeGui.PurchasedText.Visible = true
				end
				NukeSiren:Play()
				local Nuke = workspace.NukeModel
				local Fire = Nuke.FirePart.Attachment.Fire
				local CFValue = Instance.new("CFrameValue")
				CFValue.Value = Nuke:GetPivot()

				CFValue:GetPropertyChangedSignal("Value"):Connect(function()
					Nuke:PivotTo(CFValue.Value)
				end)

				local TweenTable = {
					Value = CFValue.Value * CFrame.new(1000,0,0)
				}

				local Tween = TweenService:Create(CFValue, TweenInfo.new(10, Enum.EasingStyle.Linear), TweenTable)
				for i = 10, 0, -1 do
					for _, player in Players:GetPlayers() do
						player.PlayerGui.NukeGui.RedText.Visible = true
						player.PlayerGui.NukeGui.RedText.Text = "Launching in: "..i
						NukeLaunching:Play()
					end
					task.wait(1)
				end
				for _, player in Players:GetPlayers() do
					player.PlayerGui.NukeGui.RedText.Visible = false
				end
				NukeLaunched:Play()
				Tween:Play()
				Fire.Enabled = true	
				Tween.Completed:Connect(function()
					local NewCFValue = Instance.new("CFrameValue")
					Nuke:PivotTo(CFrame.new(0,1000,0) * CFrame.Angles(0,0,math.rad(270)))
					NewCFValue.Value = Nuke:GetPivot()

					NewCFValue:GetPropertyChangedSignal("Value"):Connect(function()
						Nuke:PivotTo(NewCFValue.Value)
					end)

					local NewTweenTable = {
						Value = CFrame.new(0,0,0) * CFrame.Angles(0,0,math.rad(270))
					}

					local NewTween = TweenService:Create(NewCFValue, TweenInfo.new(9, Enum.EasingStyle.Linear), NewTweenTable)
					NukeSiren:Stop()
					NukeLanding:Play()
					NewTween:Play()
					CFValue:Destroy()
					Tween:Destroy()
					NewTween.Completed:Connect(function()
						NukeLanding:Stop()
						NukeExplosion:Play()
						local NukePart = ServerStorage.NukePart:Clone()
						NukePart.Position = Nuke.NukePartHolder.Position
						NukePart.Parent = workspace
						Nuke:Destroy()
						local NukeProperties = {
							Size = Vector3.new(800,800,800)
						}

						local NukeAnimation = TweenService:Create(NukePart, TweenInfo.new(5, Enum.EasingStyle.Linear), NukeProperties)
						NukeAnimation:Play()

						NukeAnimation.Completed:Connect(function()
							for i = 5, 0, -1 do
								for _, player in Players:GetPlayers() do
									NukeLaunching:Play()
									player.PlayerGui.NukeGui.RedText.Visible = true
									player.PlayerGui.NukeGui.RedText.Text = "Map Refreshing In: "..i
								end
								task.wait(1)
							end
							NukePart:Destroy()
							for _, player in Players:GetPlayers() do
								player.PlayerGui.NukeGui.PurchasedText.Visible = false
								player.PlayerGui.NukeGui.RedText.Visible = false
							end
							local NewNuke = ServerStorage.NukeModel:Clone()
							NewNuke.Parent = workspace
							for i = 0, 0.2, 0.001 do
								MainMusic.Volume = i
								task.wait(0.01)
							end
							NukeAnimation:Destroy()
							workspace:SetAttribute("NukeInProgress", false)
						end)
						NewCFValue:Destroy()
						NewTween:Destroy()
					end)
				end)
			else
				local config: BanConfigType = {
					UserIds = {Player.UserId},
					Duration = -1,
					ApplyToUniverse = true,
					DisplayReason = "Exploiting",
					PrivateReason = "Exploiting"
				}
				
				Players:BanAsync(config)
			end
			return Enum.ProductPurchaseDecision.PurchaseGranted

And the ban stuff is just a cooldown I made to stop players from purchasing a nuke while one is currently happening, of course exploiters can just prompt themselves to buy it with code. Which is why I have this system to check that.

Since you are destroying the tweens it should be just fine. If you do not expect the tween to be cancelled, you can opt to use :Once() rather than :Connect() as it will automatically disconnect after it’s been fired once, and help prevent leaks in case you ever forget to add :Destroy(). Other than that it looks fine, and the way you’re doing it works.

If you’re doing a quick and dirty approach, yes, this is “fine”, but there are issues that come with it, the most alarming one being higher network usage. Since it’s a nuke for a gamepass, that’s not really a concern though.

I would still recommend doing the tween client-sided anyways. It looks smoother, lowers the load on the server, and doesn’t hinder people with a worse internet connection. Whether or not you choose to is up to you though.

I always have but I just realised something, if you do a tween client-sided through fireallclients. Only the clients that are in-game will be able to witness it when the event was fired. What about players who join later? Are they just not gonna see it?

Isn’t that kind of their fault though?

Could you come check out this topic I need some help: Problem with experience transfer ownership

Could you come check out this topic please bleh? I need some help: Problem with experience transfer ownership

  1. Just replicate the current time in the tween if someone joins
  1. What…

Is that what most people do?

Well yeah, stop playing my game on mcdonalds wifi and go get some internet that actually works.