Tween between waypoint and calculate on server?

  1. What do you want to achieve? Keep it simple and clear!

Hi :smiley:

I want to know if this im doing is better way to do it?

i have made a placement system and Conveyors (Not normal Conveyors)

and that works fine and no problem there, is just that the Network Overall (KB/s) can get to like 10 or 20 or more if i place more Conveyors

the Conveyors have multiple waypoints inside them
small Conveyors = 2 waypoint
normal Conveyors = 5
xl Conveyors = 20

and right now i do calculate on the server and raycast on the server and if it find a waypoint it send data to the module script that FireClient

and when the server send data to the module then it wait for some calculate how long it gonna take tween like 2 sec and then run function again and use raycast again and that

so it keep going in a loop

but when i have like maby 30 or more that have to use the same calculate

is get a bit Network Overall (KB/s) when the module scirpt sends mutiple FireClient

  1. What is the issue? Include screenshots / videos if possible!

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    yea but if i have no idea what the best thing is for my game?
  • My server script
local localTween = require(game.ServerStorage.Modules.LocalTween)

local dispenserLevel = tonumber(script.Parent.Name:match("%d+"))

print("Dispenser Level:", dispenserLevel)

local length = 6
local speed = dispenserLevel * 1.2 + 3

local raycastParams = RaycastParams.new()

function isFacingWaypoint(bucket)

	local bucketPrimaryPart = bucket.PrimaryPart

	if bucket and bucketPrimaryPart then

		local rayDirection = bucketPrimaryPart.CFrame.LookVector

		local function createRayAndCheck(direction)

			if bucket and bucketPrimaryPart then

				raycastParams.FilterType = Enum.RaycastFilterType.Include

				local whitelist = {}

				table.insert(whitelist, script.Parent.StartWaypoint)

				for _,v in script.Parent.Parent.Parent.Conveyor:GetChildren() do
					if v:IsA("Model") then
						local WaypointsModel = v:FindFirstChild("Waypoints")

						if WaypointsModel then

							for _,j in v.Waypoints:GetChildren() do
								if j.Name == "Waypoint" then
									table.insert(whitelist, j)
								end
							end


						end
					end
				end

				for _,j in script.Parent.Parent:GetChildren() do
					if j:IsA("Model") and j:FindFirstChild("Buckets") then
						for _,v in j.Buckets:GetChildren() do
							if v:IsA("Model") and v ~= bucket then
								table.insert(whitelist, v)
							end
						end
					end
				end



				raycastParams.FilterDescendantsInstances = whitelist

				local origin = bucketPrimaryPart.Position

				local raycastResult = workspace:Raycast(origin, direction * length, raycastParams)

				if raycastResult then

					if raycastResult.Instance.Name == "PrimaryPart" then
						wait(.02)
						createRayAndCheck(rayDirection)
					elseif raycastResult.Instance.Name == "Waypoint" or raycastResult.Instance.Name == "StartWaypoint"  then		

						local Waypoint = raycastResult.Instance

						--Waypoint:SetAttribute("Claimed", true)

						local function positiveAngleDifference(angle1, angle2)
							local difference = (angle1 - angle2 + 180) % 360 - 180
							return math.abs(difference)
						end

						local rotationDifference = positiveAngleDifference(bucketPrimaryPart.Orientation.Y, Waypoint.Orientation.Y)

						if rotationDifference > 90 then
							return false
						else
							-- Tween to the waypoint
							local distance = (Waypoint.Position - bucketPrimaryPart.Position).Magnitude
							local tweenTime = distance / speed

							local tweenInfo = {tweenTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out}
							local targetCframe = {CFrame = Waypoint.CFrame}

							localTween.Tween(bucketPrimaryPart, tweenInfo, targetCframe)

							wait(tweenTime)

							bucketPrimaryPart.CFrame = Waypoint.CFrame


							if Waypoint:GetAttribute("CanLoad") then
								if Waypoint:GetAttribute("HowManyItems") > 0 then
									if bucket:GetAttribute("WhatItem") == "None" then
										if bucket:FindFirstChild("Liquid") then
											local liquid = bucket.Liquid
											local liquidTypes = game.ReplicatedStorage.Content.LiquidTypes

											for _,liquidType in liquidTypes:GetChildren() do
												if Waypoint:GetAttribute("WhatItems") == liquidType.Name then
													wait(4)
													Waypoint:SetAttribute("HowManyItems", (Waypoint:GetAttribute("HowManyItems") - 1))
													bucket:SetAttribute("WhatItem", liquidType.Name)
													liquid.Color = liquidType.Color
													liquid.Transparency = 0
													if bucket:FindFirstChild("BillboardGuiText") then
														bucket.BillboardGuiText.Frame.TextLabel.Text = liquidType.Name
														bucket.BillboardGuiText.Frame.TextLabel.TextColor3 = liquidType.Color
													end
													wait(.5)
													break
												end
											end
										end
									end
								end
							end

							--Waypoint:SetAttribute("Claimed", false)

							isFacingWaypoint(bucket)

							return true

						end
					end
				else
					return false
				end
			end
		end
		if createRayAndCheck(rayDirection) then
			return true
		else
			local n = 0
			local max = 2

			repeat

				n += 1
				wait(.001)

			until n >= max or createRayAndCheck(rayDirection)

			if n >= max then
				wait(.1)
				if createRayAndCheck(rayDirection) then
					return true
				else
					bucket:Destroy()
				end
			end
		end
	end
end


function CreateNew()
	wait(2)
	script.Parent.toggleLight.BrickColor = BrickColor.new("Lime green")
	local Clone = game.ReplicatedStorage.Content.Bucket["Bucket [Level "..dispenserLevel.."]"]:Clone()
	Clone.PrimaryPart.CFrame = script.Parent.SpawnerPoint.CFrame
	Clone.Parent = script.Parent.Buckets
	coroutine.wrap(isFacingWaypoint)(Clone)
	wait(2)
	script.Parent.toggleLight.BrickColor = BrickColor.new("Really red")	
	wait(3)
	CreateNew()
end


CreateNew()

  • My module script
local module = {}

local event = game.ReplicatedStorage.RemoteEvents.LocalTween

function module.Tween(instance, tweenInfo, properties)
	
	for _,player in game:GetService("Players"):GetChildren() do
		
		if player then
			if player.Character then 
				if (player.Character.PrimaryPart.CFrame.Position - instance.CFrame.Position).Magnitude <= 150 then
					event:FireClient(player, instance, tweenInfo, properties)
				end
			end
		end	
	end
end

return module

  • My local script
local tweenService = game:GetService("TweenService")
local event = game.ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("LocalTween")

event.OnClientEvent:Connect(function(instance, tweenInfo, properties)
	if instance then
		local tween = tweenService:Create(instance, TweenInfo.new(table.unpack(tweenInfo)), properties)
		tween:Play()
	end
end)

if you have any idea what i can try to make it better i will very happy

So basically i like Factory Simulator i think i want.

becuse they use allso tween on the ores i think??