Weld has an unexpected offset

Long story short: I have been battling all day with fixing a bug in my fishing system. There is so much absurd information about this bug, and I don’t even know where to begin. I will instead focus on the current bug.

There is a lot of code, so here is the specific snippet of what I’m trying to do. I’m attempting to weld the dipper (red part) to the handle of the fishing rod. This code worked previously (before fixing the previous bug), and now the code is creating an offset.

I have tried using both the client and server version of the dipper’s CFrame, but both of them seem to give the wrong CFrame. The dipper (red part) teleports right next to the top of the fishing rod /yellow part). Here is a picture, followed by the welding code.

The goal is make the dipper (red part) be at the same position as the RodTop (yellow part).

Image of a fish on the offset dipper:

Image of the dipper without the fish:

Weld code:

	local rodWeld = Instance.new("Weld") 
	rodWeld.Name = "RodWeld" 
	rodWeld.Part0 = dipper 
	rodWeld.Part1 = rodHandle
	rodWeld.C0 = dipperCFrame:inverse() * rodHandle.CFrame -- THIS LINE
	rodWeld.Parent = dipper

Feel free to ask for more info. I am trying not to clutter the initial post too much.

Are any of the objects unanchored?

Could you try WeldConstraint instead? It automatically calculates the offsets based on the part’s relative position

WeldConstraint gives the same result. I do suspect that the CFrame is the problem. It’s like the client and server are off sync, but even when fetching the CFrame from the client, it’s not giving the correct CFrame.

Hm, are you creaating the weld on the server or the client?

On the server.
Creating it on the client would cause some issues, but I could try it to see if it gives more hints.

I unanchor the dipper after the weld.
Here is a larger snippet.
You can see I’m invoking the client to return the CFrame of the RodTop to fix the previous bug.

	local position = dipper.Position
	local newCFrame = CFrame.new(position)
	fishInstance.MainPart:PivotTo(newCFrame)
	
	local relativePosition = dipper.CFrame:inverse() * fishInstance.MainPart.CFrame

	for index,part in ipairs(fishInstance:GetDescendants()) do
		if part:IsA("BasePart") and part.Name == "MainPart" then
			part.Anchored = true
			part.CanCollide = false
		end
	end

	dipper.Anchored = true

	local waterWeld = dipper:FindFirstChild("WaterWeld")
	if waterWeld then
		waterWeld:Destroy()
	end
	
	reel2Playing.Value = true
	ReelingPart2Event:FireClient(plr,convertedReelSpeedPart2,reel2Playing) -- Animation

	local tweenDuration = convertedReelSpeedPart2.Value
	local startTime = tick()
	
	local rodTop = dipper.Parent:FindFirstChild("RodTop")
	local startPosition = dipper.Position

	local function getTargetPosition()
		return temp:InvokeClient(plr,rodTop,dipper,"rodtop").Position
	end

	local function ease(t)
		return t * t * (3 - 2 * t)
	end
	
	while true do

		local elapsed = tick() - startTime
		local progress = math.clamp(elapsed / tweenDuration,0,1)
		local easedProgress = ease(progress)

		local targetPosition = getTargetPosition()
		
		local newDipperPosition = startPosition:Lerp(targetPosition,easedProgress)
		dipper.Position = newDipperPosition

		local spinAngle = time() * 2
		local rotationCFrame = CFrame.Angles(0,spinAngle,0)

		local newFishCFrame = dipper.CFrame * relativePosition
		fishInstance.MainPart.CFrame = newFishCFrame * rotationCFrame

		if progress >= 1 then
			
			break
			
		end

		task.wait()

	end
	
	fishInstance.MainPart.Anchored = false --Ensure player does not lift off the ground

	local fishWeld = Instance.new("Weld")
	fishWeld.Part0 = fishInstance.MainPart
	fishWeld.Part1 = dipper
	fishWeld.C0 = fishInstance.MainPart.CFrame:inverse() * dipper.CFrame
	fishWeld.Parent = fishInstance

	local rodHandle = dipper.Parent:FindFirstChild("Handle")
	
	local rodWeld = Instance.new("Weld") 
	rodWeld.Name = "RodWeld" 
	rodWeld.Part0 = dipper 
	rodWeld.Part1 = rodHandle
	rodWeld.C0 = dipper.CFrame:inverse() * rodHandle.CFrame -- THIS LINE
	rodWeld.Parent = dipper
	
	dipper.Anchored = false
1 Like

Have you checked the origin position of the parts? maybe one of them is offset

Not related but don’t use RemoteFunctions

1 Like

Sorry guys, I overlooked the fact that the fishing rod’s handle CFrame is of course also wrong on the server, so by getting the CFrame values of both the dipper and the rodHandle, the weld works properly.

Server weld:

	local rodWeld = Instance.new("Weld") 
	rodWeld.Name = "RodWeld" 
	rodWeld.Part0 = dipper 
	rodWeld.Part1 = rodHandle
	rodWeld.C0 = temp:InvokeClient(plr,rodTop,dipper,rodHandle,"dipper"):inverse() * temp:InvokeClient(plr,rodTop,dipper,rodHandle,"rodHandle") -- THIS LINE
	rodWeld.Parent = dipper

Client CFrames:

local temp = game:GetService("ReplicatedStorage"):WaitForChild("RemoteFunctions"):WaitForChild("TEMPFunction")

temp.OnClientInvoke = function(rodTop,dipper,rodHandle,identifier)
	
	if identifier == "rodtop" then
		
		return rodTop.CFrame

	elseif identifier == "dipper" then
		
		return dipper.CFrame
		
	elseif identifier == "rodHandle" then
		
		return rodHandle.CFrame

	end
	
end

If anyone knows why these server-client offsets happen. This behaviour is some of the weirdest stuff I have seen in Roblox Studio. This still does not explain the underlying behaviour of server-client replicating with offsets though.

1 Like

Yeah. I do also have the mining system in an easy-to-cheat state. Truth is that a lot of my systems (like the fishing system that is currently being debbuged) are outdated. Thanks for the video. I will look into it.

1 Like

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