Server side web swinging lagging?

Hey there! so, i made a web swinging system and i realized when i web swing, it looks like im just flying to others because its all in one local script.

So, i made it server sided as you can see here:
image

but it doesn’t work as i want it to, it lags whenever i web swing for some reason but it doesn’t with client.
Also, another bug is that randomly when i let go of mouse, it detects that i let go of mouse but unless i click and let go (again) it won’t remove the rope.

client: https://gyazo.com/199b65dc8c0c7bf3f80fd01d5f57fce5
server: https://gyazo.com/5db3540258ff64837937814124a770fb

(when receiving the remote event, i just set the variables: Able,plr,Target and Hit)
server script

task.spawn(function() --so server can still receive remotes (writing this comment, now i realized i can just put the remote above but im not doing it cuz it might mess up the code, i'll leave it up to the forums and if i can find a solution while waiting for a response.
	while task.wait() do
		if Hit and Target and plr then
			local Point = plr.Character["HumanoidRootPart"]
			local Point2 = plr.Character["Right Arm"]

			if Target and Able and Rope == nil and Target:IsA("BasePart") and (Hit.p - Point.Position).Magnitude < MD then
				Rope = Instance.new("RopeConstraint", workspace)
				Rope.Color = BrickColor.new("White")
				Rope.Visible = true
				Rope.Thickness = 0.2

				local WeldPart = Instance.new("Part",Rope)
				WeldPart.Transparency = 1
				WeldPart.CanCollide = false

				local Weld = Instance.new("Weld",WeldPart)
				Weld.Part0 = WeldPart
				Weld.Part1 = Point2

				P2 = Instance.new("Attachment",Target)
				P1 = Instance.new("Attachment",WeldPart)

				P1.WorldPosition = Vector3.new(WeldPart.Position.X,WeldPart.Position.Y,WeldPart.Position.Z)
				P2.WorldPosition = Hit.p

				local Pos = P2
				Rope.Attachment0 = P1
				Rope.Attachment1 = P2


				Rope.Length = (P1.WorldPosition - P2.WorldPosition).Magnitude + 1.2

				if not Point:FindFirstChild("BodyForce") then
					plr.Character.Humanoid.Jump = true
					F = Instance.new("BodyForce")
					F.Parent = plr.Character.HumanoidRootPart
					local Fpos = cam.CFrame.LookVector * Vector3.new(AmountOfForce,50,AmountOfForce)
					F.Force = Fpos
					--F.Force = cam.CFrame.LookVector * force
				end
			end

			if F ~= nil then
				if F.Name ~= nil then
					local Fpos = cam.CFrame.LookVector * Vector3.new(AmountOfForce,50,AmountOfForce)
					F.Force = Fpos
					--F.Force = cam.CFrame.LookVector * force
				end
			else
				if game.Workspace:FindFirstChild("RopeConstraint") then 

					game.Workspace.RopeConstraint:Destroy() 

					Rope:Destroy()
					Rope = nil
					P1:Destroy()
					P2:Destroy()
				end
			end
			if Able == false and F ~= nil and game.Workspace:FindFirstChild("RopeConstraint") then
				game.Workspace.RopeConstraint:Destroy() 
				Rope = nil
				F:Destroy()
				F = nil
			end
		end
	end
end)

Thanks!!

1 Like

You should have your web swinging on the client and send data to the server to be sent to other clients so it won’t lag for you when swinging but people will also be able to see your webs

2 Likes

How would that be done? what data would i need to send?

1 Like

Using a remote event send the position of where the webs are to the server and then from the server send this to all the clients other than the one which sent it so it can be updated for them

(Not sure exactly how you are creating the webs so you might have to send more values to the server)

Server

Event.OnServerEvent:Connect(function(PlayerSent, WebPosition)
    for Index, Player in pairs(game.Players:GetPlayers()) do
        if Player ~= PlayerSent then
            Event:FireClient(Player, WebPosition, PlayerSent)
        end
    end
end)

Client

Event:FireServer(WebPosition) -- Do when creating webs

Event.OnClientEvent:Connect(function(WebPosition, PlayerSent)
    -- Create Web for PlayerSent at WebPosition
end)
1 Like

I think i’d have to send player position too since when i use body force in the client, it doesn’t work for everyone else and when im swinging it just looks like the player swinging is flying

(I dont think sending player pos every task.wait is very good for remotes)

that will work for the webs

Yep send anything you need to create the webs to the server so it can be given to other clients as well

1 Like

Won’t it be bad to send every task.wait? Won’t the remote event tire out? specially with multiple players

(this would solve it tho xd i just dunno the approach i need to do)

I would just send data when the players clicks to make a web not every task.wait

1 Like