Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone fix this comparison error?

Asked by 8 years ago
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

Log in to vote
0
Answered by 8 years ago

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

0
Thank you for the answer, it is working well! EmperorTerminus 55 — 8y
Ad

Answer this question