So it’s my first time working with raycasts, and I’m trying to make an enemy that detects if it can see a player or not. I think I have got everything clear, but I don’t know how to get the ray to go in the player’s direction. This is the script:
local origin = script.Parent
while true do
wait(1)
for _, plr in game.Players:GetPlayers() do
local destination = plr.Character.HumanoidRootPart
local ray = workspace:Raycast(origin.Position, [DIRECTION])
if ray then
if ray.Instance.Parent.Name == plr.Name then
print(plr.Name.. " detected.")
else
print("non-player detected.")
end
else
print("nothing detected.")
end
end
end
I’ve been looking for a solution for a while, and I thought to post this here in case someone sees it and helps me, but if you’re reading this I still haven’t gotten it to work. Thank you for the help in advance!