I have this flashlight script, and in the event that triggers the light that follows the mouse
it says not a valid member, however the LightPart is RIGHT THERE
local UIS = game:GetService("UserInputService")
local character = game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local follow = false
local mouse = UIS:GetMouseLocation()
local camera = workspace.CurrentCamera
character:WaitForChild("FlashlightScript"):WaitForChild("FollowEvent").OnClientEvent:Connect(function(boolean)
local offset = Vector3.new(0, 1, 0)
follow = boolean
local weld = script.Parent:FindFirstChildOfClass("WeldConstraint")
if weld then weld:Destroy() end
while follow do
task.wait(0.01)
local ray = camera:ViewportPointToRay(mouse.X, mouse.Y)
local position = ray.Origin + ray.Direction * 10
script.Parent.LightPart.CFrame = CFrame.lookAt(position, position + ray.Direction)
end
end)
I just have no clue what’s wrong. If I do :WaitForChild(), it just has an infinite yield. I’ve checked in the explorer, and the light part is there ingame so I have no clue what’s happening