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

Is there something wrong with my script?

Asked by 10 years ago

There are no errors listed in the output and it doesn't print out line 16.(the last line of this part). The Player's TeamColor is the same as name.Name:sub(4) which is "BtnBright green". This is only PART of the script.

01function FindName()
02    for i,v in pairs(Workspace:GetChildren()) do
03        for i,a in pairs(v:GetChildren()) do
04            if a:FindFirstChild("ClickDetector") then
05                print(a)
06                return a           
07            end
08        end
09    end
10end
11local player = script.Parent.Parent.Parent.Parent
12script.Parent.MouseButton1Down:connect(function()
13    local name = FindName()
14    print(name) -- Works until next line
15    if name.Name:sub(4) == player.TeamColor then
16        print(name.."!") -- Does not show?

Please note that this is only part of the script.

2 answers

Log in to vote
1
Answered by 10 years ago

So what exactly are you trying to acomplish... It seems that the sub might mess things up. Or it may be that it's not matching the player.TeamColor, I suggest doing this:

01function FindName()
02    for i,v in pairs(Workspace:GetChildren()) do
03        for i,a in pairs(v:GetChildren()) do
04            if a:FindFirstChild("ClickDetector") then
05                print(a)
06                return a           
07            end
08        end
09    end
10end
11local player = script.Parent.Parent.Parent.Parent
12script.Parent.MouseButton1Down:connect(function()
13    local name = FindName()
14    print(name) -- Works until next line
15    if name.Name:sub(4) == player.TeamColor then
16        print(name.."!") -- Does not show?
17elseif name.Name:sub(4) ~= player.TeamColor then
18print('False')
19end
20end)

This will allow you to see if it even goes past the if, if not then the IF is incorrect.

0
I used your method and it printed out false, so then i made the teamcolor a string because i realized that teamcolor is a color not a string and now it works thanks for the help ROBLOXING213 130 — 10y
0
No problem! micke3212 35 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

It may also be that since both for loops use "i" as an index, the script may be getting confused. It's worth a shot anyways.

Just replace the first "for i,v" with "for _,v" and see if it does anything differently.

Answer this question