I’m trying to detect if a monster can see a player by casting a ray at the player’s humanoid root part.
The raycast result is empty when the ray hits the player but it does have a result when hitting any other part.
I’ve tried a ton of solutions but there is no error so it’s difficult to find the issue, especially cause I’m new to raycasting.
the stuff printing in output is the part that the ray hits
local spotted = false
while true do
if script.Parent.RayCastActive.Value == true then
print("Raycast")
local raycastresult = workspace:Raycast(script.Parent.Parent.Head.Position, game.ServerStorage.player.Value.Character.HumanoidRootPart.Position - script.Parent.Parent.HumanoidRootPart.Position)
if raycastresult then
print(raycastresult.Instance.Name)
local targetplayer = game.Players:GetPlayerFromCharacter(raycastresult.Instance.Parent)
if targetplayer then
if spotted == false then
spotted = true
print(targetplayer.Name)
game.ServerStorage.ServerComunications.HallLurkerJumpScare:Fire("Listen To the audio to make sure the HallLurker is gone")
end
end
end
end
wait(0.01)
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.