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?
