|
| 08 Oct 2017 05:21 PM |
Hello!
I've been trying to convert my Rounds death match script into a team death match Points script. I'm not getting any error outputs, however, when I set up Print tests, it successfully prints out Test2, 3, 7 and 8. I'm not sure why its skipping Test1, 4, 5, and 6. I was hoping someone could point out what I've done wrong here and some advice on how to fix it.
How the script should work:Players are put on teams automatically, Team Wizards or Team Warlocks. They are transported to a randomly chosen map. From there, once the team accumulates the maxscore for kills, in this case 10, the game ends and leaderstats for Wins, Exp, and Coins are bumped.
What its doing: Once the players are teleported to the map, its declaring Team Wizards the winner and dumping everyone back into the Lobby. As mentioned above, no error outputs, but its skipping the Prints for Test1, Test4, Test5 and Test6.
I suspect I've got my Breaks in the wrong places too, or I've overlooked something really simple.
Full Team Death Match Script:
local replicatedstorage = game:GetService('ReplicatedStorage') local status = replicatedstorage:WaitForChild('InfoValue') local mapstorage = game.workspace:WaitForChild('mapStorage') local StarterGui = game:GetService('StarterGui') local ScoreGui = StarterGui:WaitForChild('Score')
local serversettings = replicatedstorage.ServerSettings local wizardscore = serversettings.WizardScore local warlockscore = serversettings.WarlockScore
while true do if game.Players.NumPlayers < 2 then status.Value = 'There needs to be 2 or more players to begin!' repeat wait(2) until game.Players.NumPlayers >= 2 end
--Intermission for i = 20,0,-1 do --First number is the length in seconds of the Intermission status.Value = 'Intermission '..i wait(1) end
_G.gameplayers = {} for i, v in pairs(game.Players:GetPlayers()) do if v then table.insert(_G.gameplayers, v.Name) end end
-- Random Map selection & Spawns local h = Instance.new("Hint", game.Workspace) local mapsinserverstorage = game:GetService('ServerStorage').Maps:GetChildren() local chosenmap = ma########################################################c######################### mapstorage h.Text = "Be the last to survive!" status.Value = 'Now Loading: ' .. chosenmap.Name .. '! Get ready to be teleported to the map!'
wait(9) h:Destroy() local spawns = chosenmap:WaitForChild('Spawns'):GetChildren() for _, player in pairs(game.Players:GetPlayers()) do if player and #spawns > 0 then local torso = player.Character:WaitForChild('Torso') local allspawns = math.random(1, #spawns) local randomspawn = spawns[allspawns] if randomspawn and torso then table.remove(spawns, allspawns) torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
-- Grant team-specific weapons. local tool1 = game.ReplicatedStorage.AK local team1 = BrickColor.new("Pearl")
if player.TeamColor == team1 then to#################### player.Backpack end
local tool2 = game.ReplicatedStorage.IceTouch local team2 = BrickColor.new("Gold")
if player.TeamColor == te#####h#### # to#################### player.Backpack end
print("Removing ForceField1")
local players = game.Players:GetChildren() for i, plr in ipairs(players) do plr.InSafezone.Value = false end print("Removing ForceField2")
end end end
wait(1)
-- Round information for i = 10, 0, -1 do -- first number is the amount of time the Round is, the 0 is when it ends, the -1 is how fast the time goes. if i == 0 then print("Test1") status.Value = 'Time up! No winner!' break end wait(1) --local team1 = BrickColor.new("Pearl"):GetPlayers() --local team2 = BrickColor.new("Gold"):GetPlayers()
local maxscore = 10 local team1 = game.Teams.Wizards local team2 = game.Teams.Warlocks local Players = team1:GetPlayers() print("Test2") wizardscore.Value = 0 warlockscore.Value = 0 print("Test3") if wizardscore.Value == maxscore then for i,plr in pairs(team1:GetPlayers()) do
print("Test4") status.Value = 'Team 1 is the winner!' Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value + 5 -- This number is the amount of Coins awarded to the victor. Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor. Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
end if warlockscore.Value == maxscore then for i,plr in pairs(team2:GetPlayers()) do
status.Value = 'Team 2 is the winner!' Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value + 5 -- This number is the amount of Coins awarded to the victor. Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor. Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor. break end print("Test5") break else status.Value = i..' seconds remaining!' end print("Test6") end
mapstorage:ClearAllChildren() print("Test7")
wait(3) wizardscore.Value = 0 warlockscore.Value = 0 print("Test8") end end print("Test9")
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
| |
|
| |
|
|
| 09 Oct 2017 12:52 AM |
| On which line does it error? |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 09 Oct 2017 01:00 AM |
First thing I am noticing is that none of your if statements have else end in them. Important because this can cause errors, although I think they may be outputted if so?
-- Round information for i = 10, 0, -1 do -- first number is the amount of time the Round is, the 0 is when it ends, the -1 is how fast the time goes. if i == 0 then print("Test1") status.Value = 'Time up! No winner!' break else -- shouldn't end here otherwise nothing will happen unless i == 0 wait(1) |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 01:00 AM |
Thank you so much for responding! It doesn't provide an output error, but after "print test 3" it jumps ahead to "print test 7", ignoring the code in between. It also doesn't reset the values for the wizardscore.value and warlockscore.value. |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 01:15 AM |
Hanzania,
I added a few more else's to it, but I think I broke the script while doing so. :D I lose my mapstorage:ClearAllChildren() line...but after I added that first else, it kept asking for more Ends sooner in the script?
-- Round information for i = 10, 0, -1 do -- first number is the amount of time the Round is, the 0 is when it ends, the -1 is how fast the time goes. if i == 0 then print("Test1") status.Value = 'Time up! No winner!' break else wait(1) --local team1 = BrickColor.new("Pearl"):GetPlayers() --local team2 = BrickColor.new("Gold"):GetPlayers()
local maxscore = 10 local team1 = game.Teams.Wizards local team2 = game.Teams.Warlocks local Players = team1:GetPlayers() print("Test2") wizardscore.Value = 0 warlockscore.Value = 0 print("Test3") if wizardscore.Value == maxscore then for i,plr in pairs(team1:GetPlayers()) do
print("Test4") status.Value = 'Team 1 is the winner!' Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value + 5 -- This number is the amount of Coins awarded to the victor. Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor. Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
end else
if warlockscore.Value == maxscore then for i,plr in pairs(team2:GetPlayers()) do
status.Value = 'Team 2 is the winner!' Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value + 5 -- This number is the amount of Coins awarded to the victor. Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor. Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor. end end end end end
print("Test5")
end --else status.Value = i..' seconds remaining!' --end print("Test6") --end
mapstorage:ClearAllChildren() print("Test7")
wait(3) wizardscore.Value = 0 warlockscore.Value = 0 print("Test8") --end --end print("Test9") --end --end |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 09 Oct 2017 01:45 AM |
-- Round information for i = 10, 0, -1 do -- first number is the amount of time the Round is, the 0 is when it ends, the -1 is how fast the time goes. if i == 0 then print("Test1") status.Value = 'Time up! No winner!'
break else end wait(1)
--local team1 = BrickColor.new("Pearl"):GetPlayers() --local team2 = BrickColor.new("Gold"):GetPlayers()
local maxscore = 10 local team1 = game.Teams.Wizards local team2 = game.Teams.Warlocks local Players = team1:GetPlayers() print("Test2") wizardscore.Value = 0 warlockscore.Value = 0 print("Test3") if wizardscore.Value == maxscore then for i,plr in pairs(team1:GetPlayers()) do
print("Test4") status.Value = 'Team 1 is the winner!' Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value + 5 -- This number is the amount of Coins awarded to the victor. Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor. Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
end
elseif warlockscore.Value == maxscore then for i,plr in pairs(team2:GetPlayers()) do
status.Value = 'Team 2 is the winner!' Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value + 5 -- This number is the amount of Coins awarded to the victor. Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 -- This number is the amount of EXP awarded to the victor. Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1 -- This number is the amount of Wins awarded to the victor.
end else end
print("Test5")
end
--else status.Value = i..' seconds remaining!' --end print("Test6") --end
mapstorage:ClearAllChildren() print("Test7")
wait(3) wizardscore.Value = 0 warlockscore.Value = 0 print("Test8") --end --end print("Test9") --end --end |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 02:45 AM |
Hazania - Thank you, this help was invaluable. Before I saw your response, I decided to re-write the entire script, and mark which 'end' closed what on the script. When I'd finished, I had one slight error, but seeing your answer allowed me to solve it. :)
One small problem remains now, only Team 1 is getting their leaderstats bumps for the win, Team 2 does not:
-- Round information for i = 90, 0, -1 do if i == 0 then print('Test1') status.Value = 'Time Up! No Winner!' break else end -- End for Line 84 wait(1) local maxscore = 2 local team1 = game.Teams.Wizards local team2 = game.Teams.Warlocks local Players = team1:GetPlayers() print("Test2")
if wizardscore.Value >= maxscore then for i, plr in pairs(team1:GetPlayers()) do status.Value = 'Team Wizards is the Winner!' wait(1) Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value +5 Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value +1 end -- End for line 97
elseif warlockscore.Value >= maxscore then for i,plr in pairs(team2:GetPlayers())do status.Value = 'Team Warlocks is the winner!' wait(1) Players[i].leaderstats.Coins.Value = Players[i].leaderstats.Coins.Value + 5 Players[i].leaderstats.Experience.Value = Players[i].leaderstats.Experience.Value + 10 Players[i].leaderstats.Wins.Value = Players[i].leaderstats.Wins.Value + 1 end -- End for Line 106 break else end -- End for Line 96 status.Value = i..' seconds remaining!' end -- End for Line 83 mapstorage:ClearAllChildren() wizardscore.Value = 0 --Testing This warlockscore.Value = 0 -- Testing This end -- End for Line 13/While True Do |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 09 Oct 2017 04:05 PM |
if wizardscore.Value >= maxscore then elseif warlockscore.Value >= maxscore then
Both of these signs are the same >=, so if it is >= maxscore it will only go through the first one everytime.
Simple mistake haha |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 04:44 PM |
| Ah! Thank you for the response Hazania! :D I changed it to be: if wizardscore.Value == maxscore then elseif warlockscore.Value >= maxscore then And it does stop the countdown problem, but it still only gives leaderstat bumps to Team 1/Wizards and never Team ########### even if its Team 2 winning. o.o;;; I tried this: if wizardscore.Value >= maxscore or wizardscore.Value > maxscore then elseif warlockscore.Value >= maxscore or warlockscore.Value > maxscore then ^ When I do that, it comes back to the original problem of only Team1 getting the leaderstats bump, and the countdown still happening.. ...I'm gonna feel so stupid when you tell me what I should put instead of >= or == for: elseif warlockscore.Value >= maxscore then |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 04:46 PM |
(re-pasted due to previous response formatting poorly.)
Ah! Thank you for the response Hazania! :D I changed it to be:
if wizardscore.Value == maxscore then elseif warlockscore.Value >= maxscore then
And it does stop the countdown problem, but it still only gives leaderstat bumps to Team 1/Wizards and never Team 2even if its Team 2 winning. o.o;;;
I tried this:
if wizardscore.Value >= maxscore or wizardscore.Value > maxscore then elseif warlockscore.Value >= maxscore or warlockscore.Value > maxscore then
^ When I do that, it comes back to the original problem of only Team1 getting the leaderstats bump, and the countdown still happening..
...I'm gonna feel so stupid when you tell me what I should put instead of >= or == for:
elseif warlockscore.Value >= maxscore then |
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 04:56 PM |
Actually, let me correct that, the countdown problem is not solved for when Team1 wins, no matter which combination of == or >= I use.
x.x;; I know this is a simple mistake to fix too. |
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 09 Oct 2017 05:01 PM |
I actually was wrong. I misread your script.
The signs should both be >=.. Sorry!
The real error is this;
for i, plr in pairs(team1:GetPlayers()) do
-- when you set stats, use plr, not Player[i]. -- change that in both loops for warlocks and for wizards.
The reason for this is because plr in pairs sets the variable plr to be the specific child of the object you used GetPlayers() on and so it already will be set to the certain player.
The way you did it wasn't bad, just unnecessary. The reason it didn't work is because you did this;
local Players = team1:GetPlayers()
but, you used it in both loops. So if you wanted to do it that way you should have done;
local PlayersT1 = team1:GetPlayers() local PlayersT2 = team2:GetPlayers()
and then you should have used PlayersT1 in the wizard loop and PlayersT2 in the warlocks loop.
|
|
|
| Report Abuse |
|
|
|
| 09 Oct 2017 05:45 PM |
AH!!! Oh, wow...how did I make such a dumb error of not including the second local Players = team2 ? :D Wow.
Okay! I tried it both ways:
local maxscore = 2 local team1 = game.Teams.Wizards local team2 = game.Teams.Warlocks
if wizardscore.Value >= maxscore then for i, plr in pairs(team1:GetPlayers()) do status.Value = 'Team Wizards is the Winner!' print("Test3") wait(1) plr[i].leaderstats.Coins.Value = plr[i].leaderstats.Coins.Value +5 plr[i].leaderstats.Experience.Value = plr[i].leaderstats.Experience.Value + 10 plr[i].leaderstats.Wins.Value = plr[i].leaderstats.Wins.Value +1 end elseif warlockscore.Value >= maxscore then for i, plr in pairs(team2:GetPlayers()) do status.Value = 'Team Warlocks is the winner!' wait(1) plr[i].leaderstats.Coins.Value = plr[i].leaderstats.Coins.Value +5 plr[i].leaderstats.Experience.Value = plr[i].leaderstats.Experience.Value + 10 plr[i].leaderstats.Wins.Value = plr[i].leaderstats.Wins.Value +1 end
And I get this error: "1 is not a valid member of Player" referencing this line:
plr[i].leaderstats.Coins.Value = plr[i].leaderstats.Coins.Value +5
And then when I go and added: local PlayersT1 = team1:GetPlayers() local PlayersT2 = team2:GetPlayers()
and I replaced the error line above with: PlayersT2[i].leaderstats.Coins.Value = PlayersT2[i].leaderstats.Coins.Value +5
It DOES declare the team winner and award the leaderstats awards, but doesn't stop the Countdown timer.
|
|
|
| Report Abuse |
|
|
Hazania
|
  |
| Joined: 04 Jun 2010 |
| Total Posts: 1344 |
|
|
| 09 Oct 2017 11:45 PM |
Don't do plr[i], just use plr.
for i, v in pairs() do
end
i is increment which is always 1 for this type of loop v is variable and will AUTOMATICALLY update to be the child of the parameter in pairs() for each loop.
v == variable[i] |
|
|
| Report Abuse |
|
|