Not a valid member problem

I have this flashlight script, and in the event that triggers the light that follows the mouse

image

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

didnt find anything wrong with your code but your part could have spaces in them so it could be "LightPart ", this happened with me before

Yeah, i accidentally unwelded the part which caused it to fall into the void. Sorry

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.