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).
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.
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
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 dipperand 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.
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.