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

Can someone fix this comparison error?

function whenClicked()
	local wait = workspace:WaitForChild("Player")
	local playerpos = game.Workspace.Player.Torso.Position
	local leftlightpos = game.Workspace.FlashLight1.Union.Position
	local difference = playerpos - leftlightpos
	local number = 50
	if difference < number then
		local xyzb = game.Workspace.FlashLight1.Union.PointLight
		xyzb.Range = 45
	end
end

script.Parent.MouseButton1Down:connect(whenClicked)

The main goal of this script is to prevent a function from working when a player is far away from an object. Say if the player was located 55 studs away, the function would not work, however if they were 40 studs away the function would work therefore the light will turn on. However I recieve an error once this script runs. Can anyone help me?

1 answer

✓ Accepted answer

Magnitude

You need to get the magnitude of the vector, because you can't compare a number to a Vector3. if difference.magnitude < number then

1 comment

0

Thank you for the answer, it is working well!

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