You could make a part in front of the light that acts as a hitbox, and when a player touches it you could do your effect thing. Thats the simplest way.
It doesn’t make much sense on it’s own, but if you wish:
local lamp = workspace.Lamp.LampOrigin -- change to path to scp 316 --
local lookVector = lamp.CFrame.LookVector
local indicator = workspace.Lamp.Indicator -- just for visual debugging --
local originalColor = indicator.Color
local light = lamp.SurfaceLight
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {lamp, indicator}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
game:GetService("RunService").Stepped:Connect(function()
local playerInRange = false
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
if not player.Character then
continue
end
local humanoidRootPart = player.Character.HumanoidRootPart
local direction = humanoidRootPart.Position - lamp.Position
if direction.Magnitude > light.Range then
continue
end
local dotProduct = direction:Dot(lookVector)
local angle = math.deg(math.acos(dotProduct / direction.Magnitude))
print(angle)
if angle > light.Angle / 2 then
continue
end
local raycastResult = workspace:Raycast(lamp.Position, direction, raycastParams)
if not raycastResult then
continue
end
local character = raycastResult.Instance:FindFirstAncestorOfClass("Model")
if character:FindFirstChildOfClass("Humanoid") then
-- do stuff with the character here --
indicator.Color = Color3.new(1, 0.184314, 0.109804)
playerInRange = true
else
continue
end
end
if not playerInRange then
indicator.Color = originalColor
end
end)
So youre using dot products to find the angle and magnitude to find distance?
I was gonna suggest that as it produces a more cone like result but I thought using a part would be the most basic way.