Rotating part with character issue

Hello i have this little problem, I have a script where i wanna rotate a part while it moves with my character and i’m using weld to stick them together however when i try to rotate my character opposite the part that is rotating to, it kinda stops

function playerJoined(player: Player)
    print("is this working")
    player.CharacterAdded:Connect(function(character)
        print("is this working")
        local clone = helicopter:Clone()
        clone.Parent = character
        local humanoid = character:WaitForChild("HumanoidRootPart")
        clone.CFrame = humanoid.CFrame
        local motor = Instance.new("Weld")
        motor.Parent = clone
        motor.Part0 = humanoid
        motor.Part1 = clone
        RunService.Heartbeat:Connect(function()
            motor.C0 = motor.C0 * CFrame.Angles(0, math.rad(RotationSpeed), 0)
        end)
        character.Humanoid.Died:Connect(function()
            task.wait(3)
            player:LoadCharacter()
        end)
    end)
    player:LoadCharacter()
end

5 Likes

If I understand correctly you want it to move at the same absolute speed the opposite direction, not the same relative speed, incase that is right, you should just add up the delta (the change) in the rotation of the player character (e.g. humanoidrootpart) to how much you rotate the part

2 Likes

Can i ask how would you do it? i’m lost

3 Likes

So the rotation is currently connected to the Heartbeat of the game, at the end of that Heartbeat function, save the player rotation in a variable, then at the start of the next heartbeat check for the difference between the current rotation and the previous rotation, and add that many degrees to the rotationspeed

5 Likes

Alternatively, why use a weld? Appears to me this is intended behavior as its welded the rotation of the hrp will effect the rotation of the helicopter. You could work around this as @theworldis_socruel mentioned.

Why not just CFrame it without the weld? Is it for visual effect or any a specific purpose?

3 Likes

I tried just changing the cframe every frame to the players position and rotation however it lags behind, not very responsive maybe because heartbeat only has like 30 fps i think

2 Likes

Heartbeat has 60 fps, but it can desync from rendering speed if I’m not mistaken

2 Likes

Another known source of lag is if its in a server script or local script.

Doing it in a local script should solve the visual lag behind issue.

However this may cause desync and require additional replication work between clients which was why I asked if this is purely visual or gameplay related like hitboxes to better suit your case without overcomplicating the problem.

2 Likes

Well actually both, the part has attachments to which will be the hitboxes, and also for visual that’s why i’m doing it in a server script

2 Likes

Yeah i really dont know what i’m doing, can you please tell me how how to get the delta? and where do i add it up in my script

1 Like

I believe you can fix this with a heartbeat loop on the client using a local script. If im correct the current script is a server script which causes the issue lag behind issue.

Even then I do not recommend server visuals due to limited property change hz replication server to client which can cause choppy movement for rotation.

I would recommend an advanced method with a server instance for hitbox and client clone for visuals and syncing it up using a shared time method like workspace:GetServerTime.

2 Likes

I think i’ve got it now the only problem is the server actually getting the hitboxes properly, how would i time it properly

I’m using a module called Raycasthitboxes v4
and it needs to have a part because it needs attachments to work

2 Likes


Here a video for better visual for the hitboxes when i move the part in the script server is lagging behind hence the hitboxes are moving weirdly

2 Likes

Assuming the rotation works okay now, you could get the ping latency of the server compared to the client, and then add RotationSpeed * pingInSeconds to the rotation

I cant get it to work T_T the hitbox still lags behind
i’m using player:GetNetworkPing()
to get the players latency however i really have no idea how to implement it.

Just go to the heartbeat line that’s where i change the position and rotation

Also i’m noticing that when i try to get the players ping
it gives me 0 most of the time so i dont understand what’s causing the delay in the hitbox in the server

function playerJoined(player: Player)
	print("is this working")
	local ping = player:GetNetworkPing()
	player.CharacterAdded:Connect(function(character)
		print("is this working")
		local clone = helicopter:Clone()
		local hitbox = raycastHitbox.new(clone)
		local tempFilter = {}
		hitbox.Visualizer = true
		hitbox.DetectionMode = 1
		hitbox:HitStart()
		hitbox.OnHit:Connect(function(hit)
			print(hit)
			if hit:IsA("Part") or hit:IsA("MeshPart") then
				if hit.Parent.Parent.Name == "Enemy" and hit.Parent.Parent:IsA("Folder") then
					local char = hit.Parent
					local humanoid = char:FindFirstChild("Humanoid")
					if humanoid then
						table.insert(tempFilter, char)
						RaycastParamss.FilterDescendantsInstances = {table.unpack(tempFilter)}
						hitbox.RaycastParams = RaycastParamss
						hitbox:HitStop()
						hitbox:HitStart()
						humanoid:TakeDamage(10)
						task.wait(.3)
						for i,v in ipairs(tempFilter) do
							if char == v then
								table.remove(tempFilter,i)
								RaycastParamss.FilterDescendantsInstances = {table.unpack(tempFilter)}
								hitbox.RaycastParams = RaycastParamss
								return
							end
						end
					end
				end
			end
		end)
		clone.Parent = workspace
		clone.Transparency = 0
		local humanoid = character:WaitForChild("HumanoidRootPart")
		clone.CFrame = humanoid.CFrame
		RunService.Heartbeat:Connect(function()
			clone.CFrame = CFrame.new(humanoid.Position * (1)) * CFrame.Angles(math.rad(clone.Rotation.X),math.rad(clone.Rotation.Y),math.rad(clone.Rotation.Z)) * CFrame.Angles(0, math.rad(RotationSpeed), 0)
		end)
		character.Humanoid.Died:Connect(function()
			task.wait(3)
			player:LoadCharacter()
		end)
	end)
	player:LoadCharacter()
end

Oh that’s true, it should indeed be 0 as you’re in studio so the traffic between server and client should be instant… I would think the thing that’s being delayed still is your character position though?