#How to get a ray to consistently update its result?

1 messages · Page 1 of 1 (latest)

proud night
#
-- // Connections
    Connection = RunService.Heartbeat:Connect(function(DeltaTime)
        Elapsed = Elapsed + DeltaTime
        
        LinearVelocity.VectorVelocity = HumanoidRootPart.CFrame.LookVector * 100 -- Updates the directions each frame
        
        local RayOrigin = HumanoidRootPart.Position
        local RayDirection = HumanoidRootPart.CFrame.LookVector
        local RayParams = RaycastParams.new()
        RayParams.FilterType = Enum.RaycastFilterType.Exclude
        RayParams.FilterDescendantsInstances = {Character}
        local HitRay = workspace:Raycast(RayOrigin, RayDirection * 5)
        if HitRay and HitRay.Instance.Parent:FindFirstChild("Humanoid") then
            print(HitRay)
            LinearVelocity:Destroy()
            Attachment:Destroy()

            Humanoid.WalkSpeed = 16
            Humanoid.AutoRotate = true
        end
        print(HitRay)
        local Distance = (HumanoidRootPart.Position - TargetPosition).Magnitude
        if Distance <= 1 or Elapsed >= DashTime then
            if HitRay and HitRay.Instance.Parent:FindFirstChild("Humanoid") then
                print(HitRay)
                LinearVelocity:Destroy()
                Attachment:Destroy()

                Humanoid.WalkSpeed = 16
                Humanoid.AutoRotate = true
            else
                LinearVelocity:Destroy()
                Attachment:Destroy()

                Humanoid.WalkSpeed = 16
                Humanoid.AutoRotate = true
                Connection:Disconnect()
            end
            
        end
    end)
#

no pls come back 😭

jovial fable
#

come back?

proud night
#

oh i thought you left

jovial fable
#

u could do on the root part changed

#

or humanoid state changed

#

doing a heart beat each frame is not good at all

#

that would melt your pc

proud night
#

oh

proud night
#

if it changed positions?

jovial fable
#

if you wanted you can check if the humanoid root part updates(changed) or if the humanoid state changes