I’m trying to make a fishing game and I’m currently working on the fishing rod system. I want to make it similar to minecraft’s fishing; you throw the hook thingie at water and wait. I’m making it so that a hitbox (which will be placed on water) detects when the fishing hook is in it. For this I am using .Touched and .TouchEnded (which I’ve heard can be pretty bad, so I’m open to other options).
The issue is that when you unequip the fishing rod tool, TouchEnded isn’t triggered, and when you re-equip the tool, .Touched won’t fire because the script thinks that the hook is still in the hitbox.
The only solution I could think of is making it so that when unequipped, the hook goes back to the player, but this didn’t change anything. I couldn’t really find anything online so I came here.
Hitbox script (The idea is that the “physically left” print does it’s thing)
local CurrentBobbers = {}
local function RemoveFromArea(Part)
table.remove(CurrentBobbers, table.find(CurrentBobbers, Part))
print("Bobber Left")
end
script.Parent.Touched:Connect(function(Part)
print(Part.Name.. " entered")
if Part:FindFirstChild("ValidBobber") then
if Part.Parent.Parent:IsA("Tool") then
if not table.find(CurrentBobbers, Part) then
table.insert(CurrentBobbers, Part)
Part.CurrentArea.Value = script.Parent
local FishTime = 5
local FishTimePassed = 0
repeat
FishTimePassed += 1
wait(1)
until FishTimePassed == FishTime or not table.find(CurrentBobbers, Part)
if table.find(CurrentBobbers, Part) then
Part.Parent.Parent.PullTimeStart:Fire(4) -- Time and fish to earn
end
end
end
end
end)
script.Parent.TouchEnded:Connect(function(Part)
print(Part.Name.. " physically left")
if Part:FindFirstChild("ValidBobber") then
RemoveFromArea(Part)
end
end)
script.Parent.RemoveEvent.Event:Connect(function(Part)
RemoveFromArea(Part)
end)
Fishing rod server script
local Launched = false
script.Parent.ThrowBobber.OnServerEvent:Connect(function(player, MousePosition)
if Launched == false then
Launched = true
script.Parent.Model.Bobber.BobberWeld.Enabled = false
script.Parent.Model.Tip.RopeConstraint.Length = 25
local BodyVelocity = Instance.new("BodyVelocity", script.Parent.Model.Bobber)
BodyVelocity.Velocity = (CFrame.new(script.Parent.Model.Bobber.Position, MousePosition)).LookVector * 50
wait(.1)
BodyVelocity:Destroy()
else
Launched = false
script.Parent.Model.Bobber.CFrame = script.Parent.Model.BobberKeeper.CFrame
script.Parent.Model.Bobber.BobberWeld.Enabled = true
script.Parent.Model.Tip.RopeConstraint.Length = 10
end
end)
--script.Parent.
script.Parent.Equipped:Connect(function()
Launched = false
script.Parent.Model.Bobber.CFrame = script.Parent.Model.BobberKeeper.CFrame
script.Parent.Model.Bobber.BobberWeld.Enabled = true
script.Parent.Model.Tip.RopeConstraint.Length = 10
end)
script.Parent.Unequipped:Connect(function()
Launched = false
if script.Parent.Model.Bobber.CurrentArea.Value ~= nil then
script.Parent.Model.Bobber.CurrentArea.Value.RemoveEvent:Fire(script.Parent.Model.Bobber)
script.Parent.Model.Bobber.CurrentArea.Value = nil
end
script.Parent.Model.Bobber.CFrame = script.Parent.Model.BobberKeeper.CFrame
script.Parent.Model.Bobber.BobberWeld.Enabled = true
script.Parent.Model.Tip.RopeConstraint.Length = 10
end)
Thanks for reading and sorry if I’m not explaining myself correctly.