The raycast seems to be going in the wrong direction, also the neon brick in the air is the direction it’s supposed to go in.
This is the script I used
local Cam = workspace.CurrentCamera
-- Services --
local SoundService = game:GetService("SoundService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
-- Plr Objects --
local Plr = Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait()
local Head = Char:WaitForChild("Head")
-- Folders --
local Ents = workspace:WaitForChild("Entities")
-- Ents --
local Dust = Ents:WaitForChild("Dust Bunny")
-- Debounces
local Debounce = false
-- Settings --
local Params = RaycastParams.new(Enum.RaycastFilterType.Whitelist)
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {Char,workspace.Guides}
Params.IgnoreWater = true
-- Functions --
function CreateRay(Origin,Target)
-- Raycast --
local RaycastResult = workspace:Raycast(Origin.Position,Target,Params)
spawn(function()
if RaycastResult then
local Part = Instance.new("Part")
Part.Size = Vector3.new(.5,.5,RaycastResult.Distance)
Part.CFrame = CFrame.new(CFrame.new(RaycastResult.Position):Lerp(Origin,.5).Position,RaycastResult.Position)
Part.Anchored = true
Part.CanCollide = false
Part.Material = Enum.Material.Neon
Part.Parent = workspace.Guides
end
end)
print(RaycastResult)
return RaycastResult
end
-- Event Functions --
RunService.Heartbeat:Connect(function()
local TargetPos = Dust.Target.Position
local RaycastResult = CreateRay(Head.CFrame,TargetPos)
if RaycastResult then
print(RaycastResult.Instance)
print(RaycastResult.Distance)
if not RaycastResult.Instance and RaycastResult.Distance < 50 and Debounce == false then
-- BRAAM:Play()
Debounce = true
task.wait(30)
Debounce = false
end
end
end)
Example:
A direction of Vector3.new(0,-3.5,0) would start a ray going 3.5 studs down from the origin.
I think you are trying to archive to send the ray into the direction of a target. You can archive that by setting the direction to CFrame.new(origin,target).LookVector.
local RaycastResult = workspace:Raycast(Origin.Position,CFrame.new(Origin,Target).LookVector,Params)
It’s showing an error
21:03:05.869 Workspace.sparklenico20.Enemy Detection.Suspension:24: invalid argument #1 to 'new' (Vector3 expected, got CFrame) - Client
21:03:05.869 Stack Begin - Studio
21:03:05.869 Script 'Workspace.sparklenico20.Enemy Detection.Suspension', Line 24 - function CreateRay - Studio
21:03:05.869 Script 'Workspace.sparklenico20.Enemy Detection.Suspension', Line 42 - Studio
21:03:05.869 Stack End
type or paste code here
Read the error. It clearly says the stated CFrame.new requires a Vector3 but received a CFrame.
Fortunately there is a function which easily solves this error in almost every case:
Add a .Position behind your CFrame (your case: “Origin” Variable).
local RaycastResult = workspace:Raycast(Origin.Position,CFrame.new(Origin.Position,Target).LookVector,Params)