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 8 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).

local player = game.Players.LocalPlayer

player.CharacterAdded:connect(function(character)


    local scripts = character:WaitForChild("Scripts")

    for i, localscript in pairs(scripts:GetChildren()) do
        if localscript:IsA("LocalScript") then
            if not localscript.Disabled then
                localscript.Disabled = true
                localscript.Disabled = false
            end
        end
    end

    for i, gui in pairs(game.ReplicatedStorage.ServerStorage:GetChildren()) do
         if player.TeamColor == game.Teams["Axis Forces"].TeamColor then --[[ This is more reliable, change the 'Bright red Team' to your team's name. ]]
            if player.PlayerGui then
                gui:Clone().Parent = player.PlayerGui
            end

        end


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 — 8y
0
Just to add '<eof>' means end of line User#5423 17 — 8y
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 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

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

The code should look like this,

local player = game.Players.LocalPlayer

player.CharacterAdded:connect(function(character)


    local scripts = character:WaitForChild("Scripts")

    for i, localscript in pairs(scripts:GetChildren()) do
        if localscript:IsA("LocalScript") then
            if not localscript.Disabled then
                localscript.Disabled = true
                localscript.Disabled = false
            end
        end
    end

    for i, gui in pairs(game.ReplicatedStorage.ServerStorage:GetChildren()) do
         if player.TeamColor == game.Teams["Axis Forces"].TeamColor then --[[ This is more reliable, change the 'Bright red Team' to your team's name. ]]
            if player.PlayerGui then
                gui:Clone().Parent = player.PlayerGui
            end
        end
    end---two more ends
end)

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,

local player = game.Players.LocalPlayer


local scripts = player:WaitForChild("Scripts")

for i, localscript in pairs(scripts:GetChildren()) do
    if localscript:IsA("LocalScript") then
        if not localscript.Disabled then
            localscript.Disabled = true
            localscript.Disabled = false
        end
    end
end

for i, gui in pairs(game.ReplicatedStorage.ServerStorage:GetChildren()) do
     if player.TeamColor == game.Teams["Axis Forces"].TeamColor then --[[ This is more reliable, change the 'Bright red Team' to your team's name. ]]
        if player.PlayerGui then
             gui:Clone().Parent = player.PlayerGui
        end
    end
end

Good luck!

0
Thanks! It worked! BartyCrouchJunior 57 — 8y
0
No problem. User#11440 120 — 8y
0
The optimized code had a problem. I edited it. Should work now. User#11440 120 — 8y
Ad
Log in to vote
-1
Answered by 8 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 — 8y
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 — 8y

Answer this question