Hey, developers I’ve stumbled upon an issue which I don’t seem to understand and was hoping someone could reach out a solution.
The problem:
When I place a part in studio and script it to produce a ray cast, it works fine. However, if I move that part during testing then it doesn’t detect anything in front of it. When I move the part while not testing then it is able to detect an object in front of it again when I re-test. I’m not quite sure why it doesn’t update when you move it during testing or if I was to make that part move again via another script. Can someone explain to me why this happens, I am sure my code is fine but I’ll still show my code in case I’m causing the issue.
local turret = script.Parent
while wait() do
local rayCaster = workspace:Raycast(turret.Position, turret.CFrame.LookVector * 50)
if rayCaster then
print("Something was hit")
else
print("nothing is being hit")
end
end
Thank you for reading.