Hello, I made a raycast to kill players. But it won’t work, no errors. Code:
local part = game.Workspace.Part
local rayCastParams = RaycastParams.new()
rayCastParams.FilterDescendantsInstances = {game.Workspace.Baseplate, part}
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = game.Workspace:Raycast(part.Position, Vector3.new(0, 1, 0) * 50, rayCastParams)
while wait(1) do
if ray then
local hum = ray.Instance.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(100)
end
end
end
I used print statements and it showed that the problem was the code in the while loop. If you have any idea of what’s going on, please tell me. Thanks!
local rayCastParams = RaycastParams.new()
rayCastParams.FilterDescendantsInstances = {game.Workspace.Baseplate, part}
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
while wait(1) do
local ray = game.Workspace:Raycast(part.Position, Vector3.new(0, 1, 0) * 50, rayCastParams)
if ray then
local hum = ray.Instance.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(100)
end
end
end
local part = game.Workspace.Part
local rayCastParams = RaycastParams.new()
rayCastParams.FilterDescendantsInstances = {game.Workspace.Baseplate, part}
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
while wait() do
local ray = game.Workspace:Raycast(part.Position, Vector3.new(0, 0, 1) * 50, rayCastParams)
if ray then
local hum = ray.Instance.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(100)
end
end
end
Try running around the part, your direction is in world space coordinates. If you want the direction to be relative to the part you should use part.CFrame.LookVector instead of Vector3.new(0, 0, 1)
local part = game.Workspace.Part
local rayCastParams = RaycastParams.new()
rayCastParams.FilterDescendantsInstances = {game.Workspace.Baseplate, part}
rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist
while wait() do
local ray = game.Workspace:Raycast(part.Position, part.CFrame.LookVector * 50, rayCastParams)
if ray then
print("Object/terrain hit:", raycastResult.Instance:GetFullName())
print("Hit position:", raycastResult.Position)
print("Surface normal at the point of intersection:", raycastResult.Normal)
print("Material hit:", raycastResult.Material.Name)
local hum = ray.Instance.Parent:FindFirstChild("Humanoid")
if hum then
hum:TakeDamage(100)
end
else
print("No result found")
end
end
CFrame.LookVector is a Vector3 value, you can use that