How can I get rid of this error?

i’m getting this message when the result.Position it’s null. It’s ok, It should be there but is there a way to not get the message in the output window?

the script:

local plr = game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(plr.Name)
local hum = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()

UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
if gameProcessedEvent == false then
    if Input.KeyCode == Enum.KeyCode.C then
		if WeaponEquipped.Value == "Katana" then
			if CanPerformAttack == true then
				local RayOrigin = hum.Parent.HumanoidRootPart.Position
				local RayParams =
				RayParams.FilterDescendantsInstances = hum.Parent:GetChildren()
				RayParams.FilterType = Enum.RaycastFilterType.Blacklist
				RayParams.IgnoreWater = true
				local RDirection = hum.Parent.HumanoidRootPart.CFrame.UpVector * -4
				local result = workspace:Raycast(RayOrigin, RDirection, RayParams)
				if result.Position then
			        CanPerformAttack = false
					CanPerformAttack = true
1 Like

result is nil. I don’t know much about the new raycasting methods or how that would be nil, but you can do this so it won’t error.
if result and result.Position then

i wonder why i didn’t think there wouldn’t be a result. Silly me

You should consult this article: WorldRoot | Documentation - Roblox Creator Hub

It quotes: “Return and object that contains the results of a raycast operation, or nil if no eligible BasePart or Terrain cell was hit.”

Perhaps add a check to see whether result is nil or not, as the Ray may not necessarily hit something.

Hope this helps,
-Tom :slight_smile:

1 Like