Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Magnitude can't be set a distance?

while wait() do
	 for i, v in pairs(workspace:GetChildren()) do
		Human = v:FindFirstChild("Torso")
		if Human then
			print(v.Name)
			vplayer = v.Torso
		end
	end
	
	
	print((workspace.Part.Position - vplayer.Position).magnitude)
	if workspace.Part.Position - vplayer.Position.magnitude < 50 then
		print("yes")
	end

end

Everytime I run this code, it says "Workspace.Part.Script:14: bad argument #2 to '?' (Vector3 expected, got number) 11:09:01.650 - Stack Begin"

I tried putting vector3 in the beginning but did not work.

1 answer

✓ Accepted answer

As you said, magnitude is a fixed distance. However, in your function, you checked the magnitude (a number) and subtracted it from a Vector3 (the position of the part). You need to make sure to add parentheses around the area you want to take the .magnitude of.

Revised Server Script

while true do
	for i, v in pairs(workspace:GetChildren()) do
		local Human = v:FindFirstChild("Torso")
		if Human then
			print(v.Name)
			vplayer = v.Torso
		end
	end

	print((workspace.Part.Position - vplayer.Position).magnitude)
	if (workspace.Part.Position - vplayer.Position).magnitude < 50 then
		print("yes")
	end
	wait()
end

Note, vplayer should be pre-defined in some way for the script to work.

1 comment

1

Thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.