local part = game.Workspace.Part
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Workspace.Baseplate}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
while true do
wait(1)
local raycastResult = game.Workspace:Raycast(part.Position, part.CFrame.UpVector * 50, raycastParams)
if raycastResult then
print("Ray has been touched by " .. raycastResult.Instance)
end
end
The direction of the ray is up, above the part. 50 studs up. The while loop is working, I used print statements to determine which part of the loop works. And the problem of the script is this:
if raycastResult then
print("Ray has been touched by " .. raycastResult.Instance)
end
It wouldn’t print anything in this if statement and it is in the while loop. Help me please
After testing your code in a blank baseplate I noticed the print statement on line 13 errors. This could be the reason why your code doesn’t work.
Try changing line 13 to this:
print("Ray has been touched by " .. raycastResult.Instance.Name)
Full code:
local part = game.Workspace.Part
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Workspace.Baseplate}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
while true do
wait(1)
local raycastResult = game.Workspace:Raycast(part.Position, part.CFrame.UpVector * 50, raycastParams)
if raycastResult then
print("Ray has been touched by " .. raycastResult.Instance.Name)
end
end
while true do
wait(1)
local raycastResult = game.Workspace:Raycast(part.Position, part.CFrame.UpVector * 50, raycastParams)
print(raycastResult)
if raycastResult then
print("Ray has been touched by " .. raycastResult.Instance)
else
print("Nothing touched")
end
end
It’s printing in the output nil and nothing touched. Even if a part intersected with the ray.
My guess is that 1 of the parameters in the raycastResult is a invalid argument or something? Try just doing Vector3.new(0, 50, 0) instead of part.CFrame.UpVector * 50 for the second argument
Place another Part inside the workspace, move it 20 studs up & make the size large so that it’s detectable from where the original Part is supposed to be
Detect if that Part will intersect the Ray if possible?
Ok, it worked. I made a part and named it “DemoPart”. Then it printed, “Ray has been intersected by DemoPart”. But, when I remove the part in studio with the move tool… It still prints the same thing, even though I moved it away from the ray. I jumped on the part and it wont print my name.
local part = game.Workspace.Part
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Workspace.Baseplate}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
while true do
wait(1)
local raycastResult = game.Workspace:Raycast(part.Position, (part.Position + part.CFrame.UpVector * 50), raycastParams)
if raycastResult then
print("Ray has been touched by " .. raycastResult.Instance)
end
end