#Raycast bug..?

1 messages · Page 1 of 1 (latest)

kindred locust
#

The script below is a simple raycast script where a part is spawned at the end of the raycast, starting from the player position. There are random times/spots where the raycast will return "nil" even though it should not. Is this a coding error or is Roblox not functioning?

    local playerPosition = script.Parent.PrimaryPart.CFrame.Position
    local mousePosition = Player:GetMouse().Hit.Position
    local rayDirection = mousePosition - playerPosition
    local raycast = workspace:Raycast(playerPosition, rayDirection, rayParams) -- Parameters exclude the player model
    if raycast then
        print(raycast.Instance)
        local part = Instance.new("Part")
        part.Position = raycast.Position
        part.Parent = workspace
    else
        print("nil") -- Seems to fire for no reason, not sure why
    end
wanton duneBOT
#

studio** You are now Level 3! **studio

wary nexus
#

Try to extend the ray length

#

Put .unit *500 for the direction part

kindred locust
wary nexus
#

Ya

#

Try it

amber flame
#

local playerPosition = script.Parent.PrimaryPart.CFrame.Position
local mousePosition = Player:GetMouse().Hit.Position
local rayDirection = mousePosition - playerPosition
local raycast = workspace:Raycast(playerPosition, rayDirection * 1000 , rayParams) -- Parameters exclude the player model
if raycast then
print(raycast.Instance)
local part = Instance.new("Part")
part.Position = raycast.Position
part.Parent = workspace
else
print("nil") -- Seems to fire for no reason, not sure why
end

kindred locust
#

ooh yeah yeah this works now thanks!!