#Part not moving/has very slight jitter

1 messages · Page 1 of 1 (latest)

simple sonnet
#


local fish = script.Parent
fish.Anchored = true

local RNG = math.random(1, 10000)
local HRP = fish.Parent.Parent:WaitForChild("HumanoidRootPart")
local FB = HRP:FindFirstChild("FishBox")
local BE = game.ReplicatedStorage.FishSwimSystemStorage.Events.FishDestroyed

local size = FB:GetAttribute("Size")

while fish.Parent do
    
    local pos = HRP.Position
        
    local offset = {
        pos.X * RNG / 2,
        pos.Y * RNG / 2,
        pos.Z * RNG / 2
    }
    
    local bPos = pos + offset
    
    local rayOrgin = pos + Vector3.new(0, 100, 0)
    local rayDirection = Vector3.new(0, -2000, 0)
    local rayParams = RaycastParams.new()
    rayParams.IgnoreWater = true
    rayParams.FilterType = Enum.RaycastFilterType.Exclude
    rayParams.FilterDescendantsInstances = {fish}
    
    local Rayresult = workspace:Raycast(rayOrgin, rayOrgin, rayParams)
    
    local newPos = Vector3.new(bPos.X, Rayresult.Position.Y + Vector3.new(0, 1, 0), bPos.Z)
    
    local Distance = (pos - newPos).Magnitude
    
    local Speed = 1
    
    --Tweening
    
    local TimeUntilPoint = Distance / Speed
    
    local lookAt = CFrame.lookAt(fish.Position, newPos)
    local tween = TS:Create(fish, TweenInfo.new(TimeUntilPoint, Enum.EasingStyle.Linear), {
        CFrame = lookAt + (newPos - lookAt.Position)
    })
    tween:Play()
    tween.Completed:Wait()

    task.wait(RNG:NextNumber(1, 3))
    
    if not HRP or (fish.Position - HRP.Position).Magnitude > 100 or HRP.Position.Y > 50 then
        fish:Destroy()
        BE:Fire()
        break
    end
end```