Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How can I fix this ModuleScript?

Asked by
Zerio920 285 Moderation Voter
10 years ago

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

1local Library3 = require(Workspace.Start)
2script.Parent.Touched:connect(function(hit)
3if hit.Parent:FindFirstChild("Humanoid") then
4Library3.start(script.Parent.Parent.Parent)
5end
6end)

I have this in a ModuleScript:

01local Library3={}
02function Library3.start(item)
03function scan(item)
04if item:FindFirstChild("Rotor") then
05item.Rotor.BrickColor = BrickColor.new(1020)
06elseif item:FindFirstChild("Alert") then
07item.Alert.BrickColor = BrickColor.new(1020)
08item.Alert.Transparency = 0
09end
10if #item:GetChildren() > 0 then
11for _,v in pairs(item:GetChildren()) do
12scan(v)
13end
14end
15end
16end
17return 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

Log in to vote
1
Answered by 10 years ago

You have a misplaced end.

01local Library3={}
02 
03Library3["start"] = function(item)
04    function scan(item)
05        if item:FindFirstChild("Rotor") then
06            item.Rotor.BrickColor = BrickColor.new(1020)
07        elseif item:FindFirstChild("Alert") then
08            item.Alert.BrickColor = BrickColor.new(1020)
09            item.Alert.Transparency = 0
10        end
11    end
12    if #item:GetChildren() > 0 then
13        for _,v in pairs(item:GetChildren()) do
14            scan(v)
15        end
16    end
17end
18 
19return Library3

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

0
Thanks! Gonna go test it. Zerio920 285 — 10y
0
You're welcome. Please accept my answer if it does. NoahWillCode 370 — 10y
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! Zerio920 285 — 10y
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. NoahWillCode 370 — 10y
0
Ah, I see now. Thx again! Zerio920 285 — 10y
Ad

Answer this question