My ModuleScript doesnt work

  1. What do you want to achieve? I want my flashlight to flash/flicker continously (not the problem)

  2. What is the issue? Whenever I try to get the Handle of the Flashlight tool thats inside a character it gives me the error Handle is not a valid member of LocalScript "Workspace.CraftyUnknown.Flashlight"

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes I did.

Here is the code that causes the error:

function module.FlickerLights(seconds: number)
	for _, v in pairs(game.Players:GetChildren()) do
		local char = workspace:FindFirstChild(v.Name)
		print(char:GetChildren()) 
		
		if char and char:FindFirstChild("Flashlight") then
			print(char.Flashlight:GetChildren())
			
			task.spawn(function()
				for i=seconds*2,0,-1 do
					local tw = t:Create(char.Flashlight.Handle.Light,TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,true,0),{ Brightness = math.random(0,6)})
					tw:Play()
					wait(.5)
				end
			end)
		end
	end
end

Thanks in advance,
Crafty

7 Likes

Which line of the code is the error showing ? Also, as you can see the error saying “Not a valid member of LocalScript”. You may wrote something wrong.

3 Likes

What is the output of print(char.Flashlight:GetChildren())?
Because it seems that your Flashlight does not have a handle

2 Likes

Its just an empty table, I already tried that :confused:

2 Likes

I think its the tween thats trying to access the Handle

local tw = t:Create(char.Flashlight.Handle.Light,TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,true,0),{ Brightness = math.random(0,6)})
2 Likes

Is there any script in your FlashLight ? Because the error is “Handle is not a valid member of LocalScript” So the handle is present in a LocalScript which is strange.

1 Like

That means you are accessing it the wrong way, or it simply has no children.
What you can do is have a look inside your character in workspace. There you should find the Flashlight and see if it in fact has no children.

2 Likes

Yeah there are two scripts. Here is a screenshot:

image

1 Like

Already did that, when I look into it that way it has children.

image

2 Likes

So uh… Maybe, your tool has no children like @SirteXx said.

1 Like

The first table in the picture are all the children in the character. The second table are all the children in the tool Flashlight (using print(char.Flashlight:GetChildren())). And the third “print” are the values “success” and “error” from the pcall() function.

2 Likes

Here is a screenshot of the children when I look into it while in-game:

image

1 Like

Another thing that could be the cause is that the things aren’t properly loaded in yet.
try to acces the handle with local handle = char.Flashlight:WaitForChild("Handle"). That way you’d make sure it would wait until it’s loaded in.

1 Like

Well, doesnt seem to be working

You have a script inside the character called Flashlight and it is getting that over the tool.

1 Like

Ohhh, thanks!!

(had to put some text here)

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