How can I get rid of this error?

https://i.gyazo.com/ccac72b9241fa533f5c7209164f4f93a.png

https://i.gyazo.com/aee5028981becec42c88d8d9d67ebb4b.png

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 = RaycastParams.new()
				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
				    controls:Disable()
					print("First")
					module.KatanaLaunch(hum)
					print("Second") 
					CanPerformAttack = true
					controls:Enable()
				end
			end
		end
	end
end)
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