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
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
local winningAmount
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")
winningAmount = 120
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
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.
1 comment
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.