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.