Hello! The issue is that the hook for my fishing rod is either showing up in different positions for different players or not even going back to its original position at all. Here’s the code and a example picture (I’d show a video but forum doesn’t let me for some reason):
I even made the check an infinite loop in case the hook wasn’t back and it’s still not working
Additional info: The way other players see all the movement is through it being tweened by all clients through a remote event, not the server. Thought it might be important to add that.
What do you mean? It will run infinite times as long as Hook.CFrame is not equal to InvisHook.CFrame since that operation will return true which will continue the loop
also take your time and focus on class, feel free to help me once you’re home
local FishEvent = game:GetService('ReplicatedStorage'):WaitForChild('FishingRemotes'):FindFirstChild('FishEvent')
local TweenService = game:GetService('TweenService')
---
local function AdjustRopeLength(TargetHookPosition, Hook, FishingRod, RopeConstraint)
-- Calculate the distance between the rod tip and the hook
local RodTipPosition = FishingRod.RodTip.Position
local Distance = (RodTipPosition - TargetHookPosition).Magnitude
-- Set the rope constraint's length dynamically
if RopeConstraint then
RopeConstraint.Length = Distance * 1.06
end
end
local function CastFishingHook(TargetHookPosition, Hook, FishingRod, RopeConstraint)
local HookStartPosition = Hook.Position
local tweenInfo = TweenInfo.new(
2,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out
)
-- Tween to the target position
local TweenToTarget = TweenService:Create(Hook, tweenInfo, {Position = TargetHookPosition})
-- Adjust the rope length as the hook moves
TweenToTarget:GetPropertyChangedSignal("PlaybackState"):Connect(function()
if TweenToTarget.PlaybackState == Enum.PlaybackState.Playing then
AdjustRopeLength(TargetHookPosition, Hook, FishingRod, RopeConstraint)
end
end)
TweenToTarget:Play()
end
FishEvent.OnClientEvent:Connect(function(TargetHookPosition, Hook, FishingRod, RopeConstraint)
FishingRod.String.Transparency = 1
FishingRod.RodTip.StringRope.Visible = true
FishingRod.Handle["Handle-Hook"].Enabled = false
CastFishingHook(TargetHookPosition, Hook, FishingRod, RopeConstraint)
task.wait(2)
Hook.CFrame = FishingRod.InvisHook.CFrame
--Check if the Hook is already back at its original position; otherwise loop set it until it is.
while Hook.CFrame ~= FishingRod.InvisHook.CFrame do
task.wait()
Hook.CFrame = FishingRod.InvisHook.CFrame
end
FishingRod.String.Transparency = 0
FishingRod.RodTip.StringRope.Visible = false
FishingRod.Handle["Handle-Hook"].Enabled = true
end)```
I meant the line of code that fires the remote event
Just realized and came back to edit this, that is the local script. I thought “OnClientEvent” was for server scripts. But what I meant was about TargetHookPosition?
TargetHookPosition is just for the casting of the hook, it shouldn’t have anything to do with the hook returning to its original position.
This is the code that handles the returning:
Hook.CFrame = FishingRod.InvisHook.CFrame
--Check if the Hook is already back at its original position; otherwise loop set it until it is.
while Hook.CFrame ~= FishingRod.InvisHook.CFrame do
task.wait()
Hook.CFrame = FishingRod.InvisHook.CFrame
end
Btw sorry for the late reply, I had to go to sleep.
So I tried copying that script with a normal part and it only checks the position once, maybe make it so that it loops until the player is done using the fishing rod? There’s probably a better method but that’s the only one I can think of for now
Edit: It might also be that you have to set the network ownership to the server