Part Lagging On Client

Hello, So I’m working on a slapping game and I’ve ran into a problem. I’m not sure if its the way I coded it but I see that the Part I use to make the Arm follow the mouse lag’s horribly. How could I fix this and make it look smoother.

Example:

Server:

MainEvent.OnServerEvent:Connect(function(LocalPlr,Action,Mouse)
	-- Constants / Character --
	local Character = LocalPlr.Character
	local Humanoid = Character:FindFirstChild('Humanoid')
	local Head = Character:FindFirstChild('Head')
	local UpperTorso = Character:FindFirstChild('UpperTorso')
	local RightLowerArm = Character:FindFirstChild('RightLowerArm')
	local RightUpperArm = Character:FindFirstChild('RightUpperArm')
	-- Check x2 --
	if Action == 'Slapping' then
		-- Constant --
		local Walls = nil
		local Part = nil

		if not Character:FindFirstChild('Part') then
			-- Constants --
			Part = Instance.new('Part',Character)
			local ArmControl = Instance.new('IKControl',Humanoid) ArmControl.Name = 'ArmControl'
			local TorsoControl = Instance.new('IKControl',Humanoid) TorsoControl.Name = 'TorsoControl'
			-- Setup Part --
			Part.Size = Vector3.new(1,1,1)
			Part.Anchored = true
			Part.CanCollide = false
			Part.Position = Vector3.new(Head.Position.X,Head.Position.Y + 2,Head.Position.Z + 10)
			-- Set Settngs / ArmControl --
			ArmControl.Type = Enum.IKControlType.Position
			ArmControl.EndEffector = RightLowerArm
			ArmControl.Target = Part
			ArmControl.ChainRoot = RightUpperArm
			-- Set Settngs / ArmControl --
			TorsoControl.Type = Enum.IKControlType.LookAt
			TorsoControl.EndEffector = UpperTorso
			TorsoControl.Target = Part
			TorsoControl.ChainRoot = UpperTorso
		else
			Part = Character:FindFirstChild('Part')
			local ArmControl = Humanoid:FindFirstChild('ArmControl')
			local TorsoControl = Humanoid:FindFirstChild('TorsoControl')
			-- Set Settngs / ArmControl --
			ArmControl.Type = Enum.IKControlType.Position
			ArmControl.EndEffector = RightLowerArm
			ArmControl.Target = Part
			ArmControl.ChainRoot = RightUpperArm
			-- Set Settngs / ArmControl --
			TorsoControl.Type = Enum.IKControlType.LookAt
			TorsoControl.EndEffector = UpperTorso
			TorsoControl.Target = Part
			TorsoControl.ChainRoot = UpperTorso
			-- For Statement --
			for _,Station in workspace.Map.Stations:GetDescendants() do
				if Station:IsA('Model') and Station:GetAttribute('GameStarted',true) then
					-- For Statement --
					for _,Pad in Station.Queuing:GetChildren() do
						if Pad.Name == 'TeamBlue' or Pad.Name == 'TeamRed' and Pad:GetAttribute('QueuedPlr',Character.Name) then
							-- Debug --
							Walls = Station:FindFirstChild('Prevention')
						end
					end
				end
			end
			-- While Statement --
			while Character:GetAttribute('Slapping',true) do
				task.wait()
				-- Check --
				--if Mouse < Walls.Right.Position.X then
				Part.Position = Vector3.new(Mouse,Part.Position.Y,Part.Position.Z)
				--end
			end
		end

Client:

MainEvent.OnClientEvent:Connect(function(Action)
	-- Check --
	if Action == 'Slapping' then
		-- While Statement --
		while Character:GetAttribute('Slapping',true) do
			task.wait()
			-- Fire Event --
			MainEvent:FireServer('Slapping',LocalMouse.Hit.X)
		end
		-- Check --
	elseif Action == 'GetSlapped' then
		MainEvent:FireServer('GetSlapped',LocalMouse.Hit.X)
	end
end)
2 Likes

Use RunService.HeartBeat:Wait(). Is in “real time”.

1 Like

In the both or where? (char2.0)

1 Like

use Heartbeat:Wait() in both of scripts. In place of task.wait();

1 Like

Test to see if it gets smoother.

1 Like

Heartbeat:Wait() is much more recommending to use on these occasions.

2 Likes

Its smoother, but is there a way I can make it the smoothest

2 Likes

Probably with Luau Native Code Generation.

1 Like

Change the arm locally on the person who is slapping

2 Likes

If I change the entire arm movement to a client then the other client won’t be able to see it

Replicate the arm rotation manually.

I have the IKControl handle all that stuff to make it easier on my end

Ok but however your controling the arm you replicate.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.