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

Really weird script?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Hi guys! I made this script but for some reason it is completely skipping it (there is something before and after it which is not relevant to this because it runs in order down the script) Any ideas? Thanks

if game.Workspace.AllShot.Value == true then
    print("got to the allshot value")
    hdd.Text = "All the Escapers were shot!"
    wait(3)
    hdd.Text = ""
for i,v in pairs(game.Players:GetPlayers()) do
if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright blue") then
v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 100
end
end
elseif game.Workspace.AllEscaped.Value == true then
    hdd.Text = "All the Escapers escaped!"
    wait(3)
    hdd.Text = ""
    for i,v in pairs(game.Players:GetPlayers()) do
if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright green") then
v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 40
end
end
elseif game.Workspace.SomeEscapedSomeDied.Value == true then
    hdd.Text = "Some Escapers got shot, while others Escaped!"
    wait(3)
    hdd.Text = ""
    for i,v in pairs(game.Players:GetPlayers()) do
if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright green") then
v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 40
if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright green") then
v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 80

elseif game.Workspace.NothingHappened.Value == true then
print("Got to the elseif statement of nothing happened")
    hdd.Text = "No one Escaped..and no one was shot! What did you guys do? :D"
wait(3)
hdd.Text = ""
end
end
end
end
0
There doesn't seem to be anything wrong with this script at first glance. Is it inside a function? If so, make sure you're calling that function. M39a9am3R 3210 — 9y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You haven't provided the whole context, so it's hard to say what might be wrong.

I can say that this script is much messier than it needs to be -- and that cleaning it up will likely fix problems.


First, tab your code correctly.

Your code looks like this:

if game.Workspace.AllShot.Value == true then
    print("got to the allshot value")
    hdd.Text = "All the Escapers were shot!"
    wait(3)
    hdd.Text = ""
    for i,v in pairs(game.Players:GetPlayers()) do
        if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright blue") then
            v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 100
        end
    end
elseif game.Workspace.AllEscaped.Value == true then
    hdd.Text = "All the Escapers escaped!"
    wait(3)
    hdd.Text = ""
    for i,v in pairs(game.Players:GetPlayers()) do
        if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright green") then
            v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 40
        end
    end
elseif game.Workspace.SomeEscapedSomeDied.Value == true then
    hdd.Text = "Some Escapers got shot, while others Escaped!"
    wait(3)
    hdd.Text = ""
    for i,v in pairs(game.Players:GetPlayers()) do
        if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright green") then
            v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 40
            if v:findFirstChild("leaderstats") and v.TeamColor == BrickColor.new("Bright green") then
                v.leaderstats["Coins"].Value = v.leaderstats["Coins"].Value + 80

            elseif game.Workspace.NothingHappened.Value == true then
                print("Got to the elseif statement of nothing happened")
                hdd.Text = "No one Escaped..and no one was shot! What did you guys do? :D"
                wait(3)
                hdd.Text = ""
            end
        end
    end
end

Notice how line 25 and line 27 are the same? That's a mistake. Also notice how the elseif on line 30 looks like the one on 20, but isn't actually part of that? Another mistake. That's why you tab your code correctly.


Next, observe that you have very similar code ending in each if / elseif:

    wait(3);
    hdd.Text = ""
    for _, v in pairs(game.Players:GetPlayers()) do
        if v:FindFirstChild("leaderstats") and v.TeamColor == TEAM  then
            v.leaderstats.Coins.Value = v.leaderstats.Coins.Value + AMOUNT
        end
    end

-- AMOUNT and TEAM are the only things that change

You should clean that up to not be repeated (repeating code is always very bad) -- if you didn't repeat this code, you probably at least would not have made the first mistake mentioned above.

local winner -- BrickColor representing winning team
local winningAmount -- Amount of coins to give to each winner
if game.Workspace.AllShot.Value then
    hdd.Text = "All the Escapers were shot!"
    winner = BrickColor.new("Bright blue")
    winningAmount = 100
elseif game.Workspace.AllEscaped.Value then
    hdd.Text = "All the Escapers escaped!"
    winner = BrickColor.new("Bright green")
    winningAmount = 40
elseif game.Workspace.SomeEscapedSomeDied.Value then
    hdd.Text = "Some Escapers got shot, while others Escaped!"
    winner = BrickColor.new("Bright green") -- Same team as above? But more?
    winningAmount = 120 -- This is how much you were giving before
elseif game.Workspace.NothingHappened.Value then
    hdd.Text = "No one Escaped..and no one was shot! What did you guys do? :D"
end
wait(3)
hdd.Text = ""
if winner then
    -- If there was a winner...
    for _, player in pairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("leaderstats") and player.TeamColor == winner then
            player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + winningAmount
        end
    end
end

Actually, the if winner then is unnecessary (no player has a .TeamColor of nil) but it makes this clearer.

A few comments:

  • :FindFirstChild should be preferred to :findFirstChild
  • You don't need to say == true, you can just say if ....NothingHappened.Value then which reads clearer
  • Should you just use an else instead of having to actually construct a value for "NothingHappened"? It seems like "NothingHappened" should just be the absence of all other things.
  • Use meaningful variable names! Why are you using v instead of player? (If the answer is because you're typing it too much -- see repeating code is always very bad!)
  • I'm almost certain the second check for the Bright green team is not what you meant.
  • blah["Word"] is the same thing as blah.Word. When you mean blah.Word, use that, not the brackets -- it's less confusing and easier to read.
Ad

Answer this question