So I made this simple script that projects a light on the player’s cursor but I want there to be a dist limit for it
local LightSource = script.LightSource
local UIS = game:GetService("UserInputService")
local Key = Enum.KeyCode.F
local Toggled = false
local RunService = game:GetService("RunService")
local Mouse = script.Parent.Parent:GetMouse()
RunService.RenderStepped:Connect(function()
if Toggled == true then
if workspace:FindFirstChild("LightSource") then
Mouse.TargetFilter = workspace:FindFirstChild("LightSource")
workspace:FindFirstChild("LightSource").CFrame = CFrame.new(Mouse.Hit.Position + Vector3.new(0,0.5,0))
end
end
end)
UIS.InputBegan:Connect(function(input,gameProcessedEvent)
if input.KeyCode == Key and not gameProcessedEvent then
Toggled = not Toggled
if Toggled == true then
LightSource:Clone().Parent = workspace
else
if workspace:FindFirstChild("LightSource") then workspace:FindFirstChild("LightSource"):Destroy() end
end
end
end)