I’m trying to make it so a ray is casted all the time, and if a player comes in contact with it, it deals damage to them. It won’t work for some reason, wont even throw an error, could someone please help?
–Script inside of part
local origin = script.Parent.CFrame.LookVector * 300
local destination = script.Parent.Parent.Finish.Position
local direction = destination - origin
while wait() do
local raycast = workspace:Raycast(origin, destination)
if raycast then
if raycast.Instance:FindAncestorOfClass("Model") then
if raycast.Instance:FindAncestorOfClass("Model"):FindFirstChild("Humanoid") then
raycast.Instance:FindAncestorOfClass("Model"):FindFirstChild("Humanoid").Health -= 30
end
end
end
end```
local origin = script.Parent.CFrame.LookVector * 300
local destination = script.Parent.Parent.Finish.Position
local direction = destination - origin
while wait() do
local raycast = workspace:Raycast(origin, destination)
if raycast then
if raycast.Instance:FindFirstAncestorOfClass("Model") then
if raycast.Instance:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid") then
raycast.Instance:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid").Health -= 30
end
end
end
end