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
** You are now Level 3! **