How to detect if player is in a beam of Scp 316

Hello iam Sam

And now iam Trying how to make an Scp 316
I know how to make a turn on/off system

But i dont know how to detect if a player is in it beam
For more information u guys can ask in reply

I would appriciated Any help
Thanks for helping me !

2 Likes

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.

2 Likes

I can do that but what i want is the beam Of the light Sorry
Thanks for reply

Well just resize the part to be about the same size as the light.

I did say i can do that i need to take player hit the light not hit a part light that

I quickly googled scp 316, and I cobbled together some code that you can look at.
fovtest.rbxl (30.4 KB)

Can u paste since i cant download sorry

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)
3 Likes

Can ask what is Lamp.LampOrigin ? I paste the Origin position here?

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.

When I looked at the scp 316 article, this was the image of the lamp:


So I just assumed it made a cone of light.

Yeah It looks like it would be a cone shape