Hello, I was wondering how I could translate this local script to be server based (the rng and moving of the hook) as I want other players to see when someone else is fishing.
I know I have to use remote events/functions, but whatever I tried simply didn’t work or produced some horrible/completely off result.
I know the script is quite long, so if you don’t wish to read the whole thing please at least drop a comment with a way I could do this, even if it’s not specific.
local FishModule = require(script.FishModule)
local Player = game:GetService('Players').LocalPlayer
local Backpack = Player:WaitForChild("Backpack", 10)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()
local TweenService = game:GetService("TweenService")
local FishingRod = Backpack:WaitForChild("Fishing Rod Normal", 5) or Character:WaitForChild("Fishing Rod Normal", 5)
local Hook = FishingRod:WaitForChild('Hook', 20)
local RopeConstraint = FishingRod.RodTip:FindFirstChild("RopeConstraint")
if not FishingRod then
warn("Fishing rod not found!")
end
local FishCaughtGui = Player.PlayerGui:WaitForChild('FishCaughtGui')
local FishCaughtText = FishCaughtGui.FCGFrame.FishCaughtText
local OnCooldown = false
local Cooldown = 1
local function AdjustRopeLength(TargetHookPosition)
-- Calculate the distance between the rod tip and the hook
local RodTipPosition = FishingRod.RodTip.Position
local hookPosition = Hook.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)
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 dynamically as the hook moves
TweenToTarget:GetPropertyChangedSignal("PlaybackState"):Connect(function()
if TweenToTarget.PlaybackState == Enum.PlaybackState.Playing then
AdjustRopeLength(TargetHookPosition)
end
end)
TweenToTarget:Play()
end
local function GetRarityColor(ChosenRarity)
local RarityColors = {
Common = "#a9a9a9", -- Grey
Uncommon = "#00FF00", -- Green
Rare = "#0080ff", -- Blue
Epic = "#cd00cd", -- Purple
Legendary = "#FFFF00", -- Yellow
Mythical = "#ff0000", -- Red
Godly = "#00FFFF" -- Bright Blue (Cyan)
}
local RarityColor = RarityColors[ChosenRarity]
return RarityColor
end
local function IsWater(part)
-- Check if the part is a descendant of any "Water" models
while part do
if part.Name == "Water" then
return true
end
part = part.Parent
end
return false
end
local function CloseEnough()
local Distance = (FishingRod.RodTip.Position - Mouse.Hit.Position).Magnitude
if Distance <= 90 then return true
else return false
end
end
FishingRod.Activated:Connect(function()
if not OnCooldown then
OnCooldown = true
FishCaughtText.Text = 'Fishing..'
FishingRod.String.Transparency = 1
FishingRod.RodTip.RopeConstraint.Visible = true
FishingRod.Handle["Handle-Hook"].Enabled = false
local MouseTarget = Mouse.Target -- Get the target part of the mouse
if MouseTarget and IsWater(MouseTarget) then
if CloseEnough() then
local TargetHookPosition = Mouse.Hit.Position
CastFishingHook(TargetHookPosition)
task.wait(2)
local ChosenFish, ChosenNumRarity, ChosenRarity = FishModule.GetRandomFish()
local RarityColorChosen = GetRarityColor(ChosenRarity) or "#f300ff"
print(tostring(ChosenNumRarity))
print('You caught: ' .. ChosenFish .. ' (' .. ChosenRarity .. ').')
FishCaughtText.Text = 'You caught: ' .. ChosenFish .. ' (<font color="' .. RarityColorChosen .. '">' .. ChosenRarity .. '</font>).'
else
FishCaughtText.Text = 'Too far away to catch fish!'
end
else
FishCaughtText.Text = "You can only fish in water!"
end
Hook.CFrame = FishingRod.InvisHook.CFrame
FishingRod.String.Transparency = 0
FishingRod.RodTip.RopeConstraint.Visible = false
Hook.CFrame = FishingRod.InvisHook.CFrame
FishingRod.Handle["Handle-Hook"].Enabled = true
task.wait(1.5)
FishCaughtText.Text = ''
task.wait(Cooldown)
OnCooldown = false
else
print('On cooldown.')
end
end)