Fishing rod won't do anything when activated

I just spent 4 days making a fishing rod. The rod only uses one big piece of code (and a little 5 line server script for when the player catches a fish).

The problem is that for some reason when the rod is activated, nothing happens. It dose not output any errors or warnings at all. Does anyone know why?

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local FishingRod = script.Parent
local Settings = FishingRod:WaitForChild("Settings")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage.Modules
local FishingModule = require(Modules.FishingModule)
local ToastModule = require(Modules.ToastNotifications)

local HookIndicator = FishingRod.HookDisplay.BillboardGui.ImageLabel
local HookIndicatorTween = game:GetService("TweenService"):Create(HookIndicator, TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, false, 0), {Size = UDim2.new(1, 0, 1, 0)}):Play()

local Players = game:GetService("Players")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Constraints = FishingRod.Constraints
local Line = Constraints.Line
local In = Constraints.In

local Hook = FishingRod.Hook

local Humanoid = Character:WaitForChild("Humanoid")
local Animations = FishingRod.Animations

local CastAnimation = Humanoid:LoadAnimation(Animations.CastFishingRod)
CastAnimation.Looped = false

local HoldAnimation = Humanoid:LoadAnimation(Animations.HoldFishingRod)
HoldAnimation.Looped = true

local MAX_MOUSE_DISTANCE = 110
local MAX_ROD_DISTANCE = 100

local GUI = FishingRod:WaitForChild("FishingIndicator")

local Status = FishingRod:WaitForChild("Status")

local IsCast = Status.IsCast
local IsFish = Status.IsFish
local IsReeling = Status.IsReeling

local ReelingNumber = 0

local CurrentGui = nil

local DBA = false

local TotalFish = ReplicatedStorage.Fishing.Fish:GetChildren()

function AnimateIndicator(On)
	if On == true then
		HookIndicator.Visible = true
	else
		HookIndicator.Visible = false
	end
end

function Cast()
	if Player.Bait.CurrentBait.Value ~= nil and Player.Hooks.CurrentHook.Value ~= nil then
		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 = {Character}
		local raycastResult = workspace:Raycast(screenToWorldRay.Origin, directionVector, weaponRaycastParams)

		if raycastResult then

			if raycastResult.Position then

				local targetDirection= (raycastResult.Position - FishingRod.Handle.Position).Unit
				local directionVector = targetDirection * MAX_ROD_DISTANCE

				local weaponRaycastParams = RaycastParams.new()	
				weaponRaycastParams.FilterDescendantsInstances = {Players.LocalPlayer.Character}

				local weaponRaycastResult = workspace:Raycast(FishingRod.Handle.Position, directionVector, weaponRaycastParams)

				if weaponRaycastResult then

					local hitPosition = weaponRaycastResult.Position
					local Material = weaponRaycastResult.Material

					if Material == Enum.Material.Water and hitPosition then
						Character.HumanoidRootPart.Anchored = true
						Hook.Massless = false
						IsCast.Value = true
						Line.Length = 20
						local TMP = Instance.new("Model", workspace)
						TMP.ModelStreamingMode = Enum.ModelStreamingMode.Persistent

						local TMPP = Instance.new("Part", TMP)
						TMPP.Transparency = 1
						TMPP.CanCollide = false
						TMPP.Anchored = true
						TMPP.Position = raycastResult.Position

						local EndForceAttatchment = Instance.new("Attachment", TMPP)
						EndForceAttatchment.WorldCFrame = TMPP.CFrame

						local Force = Instance.new("LineForce", Constraints)
						Force.Enabled = true
						Force.Attachment0 = Hook.ForceAttatchment
						Force.Attachment1 = EndForceAttatchment
						Force.Magnitude = 8000
						Force.ApplyAtCenterOfMass = true
						In.Enabled = false
						task.wait(0.2)
						Force:Destroy()
						TMPP:Destroy()
					end
				end
			end
		end
	else
		ToastModule.CreateToast(Player, "NoBaitOrHookSelectedToast", "Please select a hook and bait.", "Can't catch a fish without a hook and bait, right?", "rbxassetid://10594389133", 3)
	end
end

function Reel()
	IsCast.Value = false
	Line.Length = 0.1
	task.wait(1)
	In.Enabled = true
	Hook.Massless = true
	Character.HumanoidRootPart.Anchored = false
	FishingRod.HookDisplay.Bubbles.Enabled = false
	IsFish.Value = false
end


function Activated()
	if IsCast.Value == false and IsFish.Value == false and IsReeling.Value == false then
		Cast()
	elseif IsFish.Value == true and IsCast.Value == true and IsReeling.Value == false then
		Fish()
	elseif IsCast.Value == true and IsFish.Value == false and IsReeling.Value == false then
		Reel()
	end
end

local ActivatedConnection = FishingRod.Activated:Connect(Activated)

function Fish()
	IsReeling.Value = true
	IsFish.Value = false
	IsCast.Value = false
	
	CurrentGui = GUI:Clone()
	CurrentGui.Parent = Player.PlayerGui

	local Sucess = true

	ReelingNumber = 50

	ActivatedConnection:Disconnect()

	local IncreseConnect = FishingRod.Activated:Connect(function()
		ReelingNumber = ReelingNumber + 10
		if ReelingNumber >= 100 then
			Sucess = false
		end
	end)

	task.wait(math.random(10, 20))

	IncreseConnect:Disconnect()

	IsReeling.Value = false
	task.wait(2)

	CurrentGui:Destroy()

	Reel()
	print("It worked and the result is: ")
	print(Sucess)
	
	if Sucess == true then
		local Fish = nil
		repeat
			local TheChosenOne = TotalFish[math.random(1, #TotalFish)].Name
			if FishingModule:DoseItWork(Player.Bait.CurrentBait.Value.Name, TheChosenOne) == true then
				Fish = TheChosenOne
			end
		until Fish ~= nil
		local SucessMessage = "You caught a " .. Fish
		ToastModule.CreateToast("FishLostToast", SucessMessage, "Good job!", game.ReplicatedStorage.Fishing.Fish:FindFirstChild(Fish).TextureId, 3)
		ReplicatedStorage.FishCaught:FireServer(Fish)
	else
		ToastModule.CreateToast("FishLostToast", "Fish Lost", "Better luck next time.", "rbxassetid://10594389133", 3)
	end

	ActivatedConnection = FishingRod.Activated:Connect(Activated)
end

function Equiped()
	HoldAnimation:Play()
end

function Unequiped()
	Reel()
	
	HoldAnimation:Stop()
	
	IsReeling.Value = false
	IsCast.Value = false
	IsFish.Value = false
	
	if CurrentGui then
		CurrentGui:Destroy()
	end
	
	Character.HumanoidRootPart.Anchored = false
	
	HookIndicator.Visible = false
end


FishingRod.Equipped:Connect(Equiped)
FishingRod.Unequipped:Connect(Unequiped)

IsCast.Changed:Connect(AnimateIndicator)

while task.wait() do
	if IsReeling.Value == true then
		task.wait(math.random(0.1, 0.2))
		ReelingNumber = ReelingNumber - 1
		if CurrentGui ~= nil then
			if CurrentGui:FindFirstChild("Frame") then
				CurrentGui.Frame.ImageLabel.Indicator.Position = UDim2.new(ReelingNumber/100, 0, 0.5, 0)
			end
		end	
	elseif IsCast.Value == true then
		task.wait(math.random(10, 20))
		IsFish.Value = true
		FishingRod.HookDisplay.Bubbles.Enabled = true
		task.wait(math.random(1.5, 5))
		IsFish.Value = false
		FishingRod.HookDisplay.Bubbles.Enabled = false
	end
end
1 Like

One problem is the Fish() function is under the Activated() function, so it won’t be able to call on it. Try moving the Fish() function above Activated()

I can’t, it needs the ActivatedConnection.

Never mind everyone, I figured out the problem.

There was an invisible can query part that was stopping the ray cast.

By the way, for future reference. It does work and you don’t need to move the function. Just thought you might like to know. I thought that might be a problem too, but it turns out it’s not.

2 Likes

I didn’t know that, thanks for telling me!

1 Like

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