Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I fix this ModuleScript?

Bear with me here, please. I have this script in a brick:


local Library3 = require(Workspace.Start)
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
Library3.start(script.Parent.Parent.Parent)
end
end)

I have this in a ModuleScript:


local Library3={}
function Library3.start(item)
function scan(item)
if item:FindFirstChild("Rotor") then
item.Rotor.BrickColor = BrickColor.new(1020)
elseif item:FindFirstChild("Alert") then
item.Alert.BrickColor = BrickColor.new(1020)
item.Alert.Transparency = 0
end
if #item:GetChildren() > 0 then
for _,v in pairs(item:GetChildren()) do
scan(v)
end
end
end
end
return Library3

When a player touches the brick, it's supposed to call the module script, which is then supposed to scan all the bricks in the model to find "Alert" and "Rotor" and make the necessary changes to their properties. Touching the brick produces no effect however. Anything I'm doing wrong here?

1 answer

✓ Accepted answer

You have a misplaced end.

local Library3={}

Library3["start"] = function(item)
	function scan(item)
		if item:FindFirstChild("Rotor") then
			item.Rotor.BrickColor = BrickColor.new(1020)
		elseif item:FindFirstChild("Alert") then
			item.Alert.BrickColor = BrickColor.new(1020)
			item.Alert.Transparency = 0
		end
	end
	if #item:GetChildren() > 0 then
		for _,v in pairs(item:GetChildren()) do
			scan(v)
		end
	end
end

return Library3

REMEMBER Formating is IMPORTANT. Readability is arguably more important than Functionality.

5 comments

0

Thanks! Gonna go test it.

0

You're welcome. Please accept my answer if it does.

0

It works! Can't believe all this time it was a simple misplace. I've been looking everywhere for an answer to this, thank you!

0

You're very, VERY welcome!! A great tip is to FORMAT your code. I noticed none of your code was tabbed out, so the first thing I did was format it, and that helped me find the error within seconds.

0

Ah, I see now. Thx again!

This discussion is preserved as it was. New answers, comments, and votes are closed.