Arithmetic error?

Hello!

I’m fairly new to the world of scripting, so this post might seem a little dumb or unnecessary to some more advanced scripters, but I can’t figure this error.

I’m currently working on a sort of parkour game and am trying to implement a grapple feature. The basics of it is, if the player is within range they can click on the object and grapple to it. I am currently experiencing issues with the proximity feature.

mouse.Button1Down:Connect(function()
	
	local distance = 20 -- whatever number

	if (player.Character.HumanoidRootPart.Position - GrappleObject.Position).Magnitude >= distance then
		print(GrappleObject.Position)
		GrappleEvent:FireServer()
		
		print("Fired GrappleEvent")
	else
		-- dont grapple
	end
end)

Every time I attempt to grapple to the part I get returned with this error:

Workspace.Player.Grapple:16: attempt to perform arithmetic (sub) on Vector3 and nil

The error is being caused on this line:

if (player.Character.HumanoidRootPart.Position - GrappleObject.Position).Magnitude >= distance

Its probably a simple solution, I just can’t find it.

The error is saying that the property Position doesn’t exist for GrappleObject

1 Like

How would I define or get the Position for GrappleObject?

Would I be able to define it in a variable?

Where do you define GrappleObject

I just figured it out! Very simple solution, the way GrappleObject was being defined was:

local GrappleObject = CollectionService:GetTagged(“Grapple”)

I dont even know why it was defined as that, but, defining it as:

local GrappleObject = game.Workspace.GrappleObject

seemed to do the trick.

Thanks for the help!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.