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

What is wrong with this Local Script?

Asked by 9 years ago

The script is supposed to clone a specific GUI based on the character's team. It is a local script, and located in Replicated First. (ServerStorage is a Folder in Replicated Storage incase anyone was wondering).

01local player = game.Players.LocalPlayer
02 
03player.CharacterAdded:connect(function(character)
04 
05 
06    local scripts = character:WaitForChild("Scripts")
07 
08    for i, localscript in pairs(scripts:GetChildren()) do
09        if localscript:IsA("LocalScript") then
10            if not localscript.Disabled then
11                localscript.Disabled = true
12                localscript.Disabled = false
13            end
14        end
15    end
View all 23 lines...

Output reads: ReplicatedFirst.LocalScript:25: 'end' expected (to close 'for' at line 17) near '<eof>'

1
you're missing an end. This one is easy dude. theCJarmy7 1293 — 9y
0
Just to add '<eof>' means end of line User#5423 17 — 9y
0
Is he missing two ends? I think so. You need on regular end and another after the first like this end) both at the end of the script. User#11440 120 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

You're missing two ends to end your for loop and function.

The code should look like this,

01local player = game.Players.LocalPlayer
02 
03player.CharacterAdded:connect(function(character)
04 
05 
06    local scripts = character:WaitForChild("Scripts")
07 
08    for i, localscript in pairs(scripts:GetChildren()) do
09        if localscript:IsA("LocalScript") then
10            if not localscript.Disabled then
11                localscript.Disabled = true
12                localscript.Disabled = false
13            end
14        end
15    end
View all 24 lines...

That should stop the errors.

There is just a small optimization issue that's annoying me. You used a player added function where one is not needed. The script will not run until it gets Replicated To the player. Meaning we can safely run the code knowing it will only run for that local player from the beginning of the script. Here's what the optimized script will look like,

01local player = game.Players.LocalPlayer
02 
03 
04local scripts = player:WaitForChild("Scripts")
05 
06for i, localscript in pairs(scripts:GetChildren()) do
07    if localscript:IsA("LocalScript") then
08        if not localscript.Disabled then
09            localscript.Disabled = true
10            localscript.Disabled = false
11        end
12    end
13end
14 
15for i, gui in pairs(game.ReplicatedStorage.ServerStorage:GetChildren()) do
View all 21 lines...

Good luck!

0
Thanks! It worked! BartyCrouchJunior 57 — 9y
0
No problem. User#11440 120 — 9y
0
The optimized code had a problem. I edited it. Should work now. User#11440 120 — 9y
Ad
Log in to vote
-1
Answered by 9 years ago

Put an end like this: end) at the end of the whole script.

0
Still doesn't work for some reason... BartyCrouchJunior 57 — 9y
0
Okay, try this remove the end that is at the end at put it before the for in statement on line 16 like this: end) that should work. TheDexterousBuilder 0 — 9y

Answer this question