Magnitude Errors

The error I’m getting:

20:53:04.310 - magnitude is not a valid member of Part

My ServerScript (In a part, located in workspace, in a Fire model):

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		print(player.Name)
		local purpose = "Fire"
		game.ReplicatedStorage.GUIs.ShowInteraction:FireClient(player, purpose, script.Parent)
		print("success")
	end
end)

And finally my LocalScript (In a GUI, in PlayerGui):

game.ReplicatedStorage.GUIs.ShowInteraction.OnClientEvent:Connect(function(purposeOfInteraction, partFired)
	print("received event")
	if purposeOfInteraction == "Fire" then
		if game.Players.LocalPlayer.Character.HumanoidRootPart.magnitude - partFired.Parent.FirePart.magnitude <= 3 then
			script.Parent.Visible = true
		else
			script.Parent.Visible = false
		end
	end
	
	local UIS = game:GetService("UserInputService")
	local IKey = Enum.KeyCode.I
	local function IisDown()
		return UIS:IsKeyDown(IKey)
	end
	local function IisDownCont(input, gameProcessedEvent)
		if IisDown() then
			if purposeOfInteraction == "Fire" then
				if game.Players.LocalPlayer.Character.HumanoidRootPart.magnitude - partFired.Parent.PrimaryPart.magnitude <= 3 then
					while true do
						wait(3)
						game.Players.LocalPlayer.Statistics.Warmth.Value = game.Players.LocalPlayer.Statistics.Warmth.Value + 10
					end
				else
					script.Parent.Visible = false
				end
			end
		end
	end
	UIS.InputBegan:connect(IisDownCont)
end)

Thanks for the help, and if anything needs clarification, I’m all ears.

Change that to

(game.Players.LocalPlayer.Character.HumanoidRootPart - partFired.Parent.FirePart).Magnitude

as well as anywhere else you made this mistake.

Magnitude is a property of Vector3, that’s your issue

You subtract the position from the other position, then get the magnitude of that

(Player.Character.HumanoidRootPart.Position - partFired.Parent.FirePart.Position).Magnitude

2 Likes

Thanks! I don’t work with this very often, so it’s nice to know this. Thanks!

If I helped you can you mark as the solution my post.

Yup, I did, if you can see that. :slight_smile:

1 Like