Problem with fishing rod

Basically, for a group game I’ve been trying to script a fishing rod my goal is to create a functional fishing rod

So I’m midway trough making it but I got a problem, the second time you use the fishing rod the hook doesn’t move even more surprising, the problem only appears on the client who used the fishing rod.

It’s very confusing for me, I can’t find any post about the issue I’m having. here’s the current script

the local script in the tool

local tool = script.Parent
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local IsUsingRod = false

local MAX_MOUSE_DISTANCE = 110
local MAX_ROD_DISTANCE = 100

local function getWorldMousePosition()
	local mouseLocation = UserInputService:GetMouseLocation()
	local screenToWorldRay = workspace.CurrentCamera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
	local directionVector = screenToWorldRay.Direction * MAX_MOUSE_DISTANCE
	local weaponRaycastParams = RaycastParams.new()
	weaponRaycastParams.FilterDescendantsInstances = {Players.LocalPlayer.Character}
	local raycastResult = workspace:Raycast(screenToWorldRay.Origin, directionVector, weaponRaycastParams)
	if raycastResult then
		return raycastResult.Position
	end
end

local function fireWeapon()
	local mouseLocation = getWorldMousePosition()
	if mouseLocation then
		local targetDirection = (mouseLocation - tool.Handle.Position).Unit
		local directionVector = targetDirection * MAX_ROD_DISTANCE
		local weaponRaycastParams = RaycastParams.new()
		weaponRaycastParams.FilterDescendantsInstances = {Players.LocalPlayer.Character}
		local weaponRaycastResult = workspace:Raycast(tool.Handle.Position, directionVector, weaponRaycastParams)
		if weaponRaycastResult then
			local hitPosition = weaponRaycastResult.Position
			local Material = weaponRaycastResult.Material
			if Material == Enum.Material.Water and hitPosition and Players.LocalPlayer:GetAttribute("Baits") >= 1 and IsUsingRod == false then
				Players.LocalPlayer:SetAttribute("Baits", Players.LocalPlayer:GetAttribute("Baits") - 1)
				IsUsingRod = true
				local Animator = Players.LocalPlayer.Character.Humanoid.Animator
				local Swing = Instance.new("Animation")
				Swing.AnimationId = "rbxassetid://12646581867"
				local SwingTrack = Animator:LoadAnimation(Swing)
				SwingTrack.Priority = Enum.AnimationPriority.Action
				SwingTrack.Looped = false
				SwingTrack:Play()
				SwingTrack:AdjustSpeed(.35)
				Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
				game.ReplicatedStorage.FISHING:FireServer(mouseLocation)
				SwingTrack.Stopped:Wait()
				wait(10)
				IsUsingRod = false
				Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
			end
		end
	end
end

tool.Activated:Connect(fireWeapon)

the script in ServerScriptService

local Event = game.ReplicatedStorage.FISHING

Event.OnServerEvent:Connect(function(player, GoalPos)
	local Rod = player:FindFirstChild("Fishing rod")
	if not Rod then
		Rod = player.Character:FindFirstChild("Fishing rod")
	end
	wait(.8)
	Rod.Handle.Weld.Enabled = false
	Rod.FishHook:PivotTo(CFrame.new(GoalPos))
	wait(10)
	local RodPivot = Rod.Handle:GetPivot()
	Rod.FishHook:PivotTo(RodPivot * CFrame.new(0,-1,0))
	Rod.Handle.Weld.Enabled = true
end)

I know my code is very bad but all I want is the solution to the problem I currently have.
Most of the code here is working. I’m very confused by this and in case you’re wondering, no error in the output.

I eventually found out by myself but didn’t want to give myself a solution so I’m saying that’s the solution.

Your local script does not do anything with the rod itself, so I would rule it out. I think the problem is with network ownership of the player character and that the rod is parented to the character. Parenting stuff to the character usually results in different behaviour on client than on server for such parts.

I am a bit confused about this part:

local Rod = player:FindFirstChild("Fishing rod")
	if not Rod then
		Rod = player.Character:FindFirstChild("Fishing rod")
	end

Does that mean that the rod can be parented to the player? That is definitely wrong, and it should never be the case (unless it is in the backpack).

Tools are weird this way, and unless you are anchoring the parts their behaviour will strongly depend on the client.

Anyways try to parent the rod to the workspace and see if that solves the issue. If it does, that means you will have to find a different solution to what you are currently doing.

Yeah the part having the rod parented to the player is a mistake of mine I just forgot to write “.Backpack” Anyways when I parent it to the workspace and take it then the rod still haves the same problem. Using my experience, anchoring a tool makes moving with it impossible.

Hmm, I was wrong then.

Do you have any local scripts, other than the one you showed, that do anything with the fishing rod?

No I showed everything. I’m going to try ruling out the local script

I am guessing here, but maybe try to reduce the timeout on the server to 8-9 seconds, to make sure the spamming does not play a role here. I am thinking that if the player spams the mouse click, they might just activate the rod before the server got a chance to reset it.

Ideally the server should fire the client an event that the rod is ready to use again.

My plan about the timeout of 10 seconds is that there’s 5 seconds of wait, then 5 seconds where you have to get an high cps to catch a fish (changing depending on the fish).

My fishing rod has another problem, this one is directly on the server, so the problem is that when the fishing rod comes back the fishing rod goes directly at the place I need it to go, but the second time it doesn’t, something changes after the first time you fish I don’t know what but if we find it 2 problems are gonna be solved.

Btw I don’t know how to play animations from a non local script.

I learnt about tweens right now and thought it was a great idea to use them for the fishing rod. It fixed both problems.

I don’t want to give myself a solution, I’m going to award it to the only one who responded.

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