Rayasting from the player’s head part doesn’t seem to be working, the Raycast orientation is incorrect. What am I doing wrong here? The “light” part should be updating when there’s a Raycast hit, but it’s definitely not casting properly.
local light = workspace:WaitForChild("Part",1) or game:GetService("ReplicatedStorage"):WaitForChild("Part")
light.Parent = workspace
local param = RaycastParams.new()
param.FilterDescendantsInstances = {script.Parent:GetChildren(),light}
param.FilterType = Enum.RaycastFilterType.Blacklist
local head = script.Parent:WaitForChild("Head")
while task.wait(.1) do
local source = head.CFrame
local result = workspace:Raycast(source.Position, source.LookVector * Vector3.new(0, 0, 100), param)
if result then
local distance = result.Distance
light.Size = Vector3.new(light.Size.X, light.Size.Y, distance)
light.CFrame = CFrame.lookAt(source.Position + Vector3.new(0,0,-distance/2), source.LookVector * Vector3.new(0, 0, -distance/2))
end
end
The raycast functions identically, as the filtered instances may be in a redundant form, they’re still valid instances that filter the same. The problem is the orientation of the raycast seemingly staying the same, but I’m not sure why.
Being in close proximity to spawn, it works as intended.
If I scale the part down to half a stud thick, and make it .5 Transparency, so we can see what happens from first person perspective, and I move around…
it’s not perfectly aligned with your canera because of lag and character animations
it looks like maybe the wait(0.1) and/or handling the cframing on serverside (and making you wait for your ping) is causing delays
for the light not updating while you’re on the side of the building, maybe you didnt set all of the building’s parts to CanQuery=true?
you could try using the output to print result each iteration too
This is ran using a local script, nothing server-side, the structure is only made from basic parts, and the raycast localscript is the only script. CanQuery isn’t available in properties anymore, oddly. EDIT I disabled CanCollide, when CanQuery became visible, it was already enabled for all the parts.
Here’s the output for the raycast result, and its distance.
I was convinced it was an engie bug… But there they were, all the heroes who commented. Thank you all for helping me figure this out.
As a reward, all of the users here get a free commission of your choice. Aside from the most advanced scripting, I can literally do anything involved with game development, rather well. Drop me a message, and name your prizes.