chess123mate

ScriptingHelpers Full Simplified Script

Oct 13th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. local teamtaking = script.Parent:WaitForChild("teamtaking")
  2. local team = script.Parent:WaitForChild("team")
  3. local flag = script.Parent:WaitForChild("flag")
  4. local poleTag = script.Parent:WaitForChild("pole").BillboardGui.tag -- you could also wait for BillboardGui and tag here if you wanted
  5.  
  6. local number = 0
  7. local max = 13
  8.  
  9. function setNumber(newNumber)
  10.     number = newNumber
  11.     local absNumber = math.abs(newNumber)
  12.     if absNumber > max then return end
  13.     flag.CFrame = CFrame.new(126.961, 377.416 + absNumber, -419.518)
  14. end
  15. function recordTeamIsCapturing(teamName, flagColor, poleColor, captureDir, modelName)
  16.     -- returns true if the team successfully captured the flag
  17.     -- teamName: "R", "B", etc
  18.     -- captureDir: what to change 'number' by (-1 or 1)
  19.     -- modelName: the name of the model in script.Parent to reward players by (ex "rplayers" or "bplayers")
  20.     if number == 0 then
  21.         flag.BrickColor = flagColor
  22.         poleTag.BackgroundColor3 = poleColor
  23.     end
  24.     setNumber(number + captureDir)
  25.     local plr
  26.     for _, player in ipairs(script.Parent[modelName]:GetChildren()) do
  27.         local plr = game.Players:GetPlayerFromCharacter(player.Value)
  28.         if plr then
  29.             plr.playerpointstore.Value = plr.playerpointstore.Value + 10
  30.         end
  31.     end
  32.     if number == max * captureDir then
  33.         team.Value = teamName
  34.         return true
  35.     else
  36.         return false
  37.     end
  38. end
  39. local db = false
  40. function flag()
  41.     if db then return end
  42.     db = true
  43.     local captured
  44.     while true do
  45.         if teamtaking.Value == "R" and number ~= max then
  46.             captured = recordTeamIsCapturing("R", BrickColor.new("Bright red"), Color3.new(1,0.137254902,0.137254902), 1, "rplayers")
  47.             if captured then break end
  48.         elseif teamtaking.Value == "B" and number ~= -max then
  49.             captured = recordTeamIsCapturing("B", BrickColor.new("Bright blue"), Color3.new(0.137254902,0.137254902,1), -1, "bplayers")
  50.             if captured then break end
  51.         elseif teamtaking.Value == "N" then
  52.             if team.Value == "R" and number ~= max then
  53.                 setNumber(number + 1)
  54.                 if number == max then break end
  55.             elseif team.Value == "B" and number ~= -max then
  56.                 team.Value = "B"
  57.                 if number == -max then break end
  58.             elseif team.Value == "N" then
  59.                 if number < 0 then
  60.                     setNumber(number + 1)
  61.                 elseif number > 0 then
  62.                     setNumber(number - 1)
  63.                 end
  64.                 if number == 0 then
  65.                     flag.BrickColor = BrickColor.new("Institutional white")
  66.                     poleTag.BackgroundColor3 = Color3.new(1,1,1)
  67.                     break
  68.                 end
  69.             end
  70.         end
  71.         wait(1)
  72.     end
  73.     db = false
  74. end
  75. teamtaking.Changed:connect(function()
  76.     flag()
  77. end)
Advertisement
Add Comment
Please, Sign In to add comment