Guest User

Untitled

a guest
Apr 17th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. -- FlagScript
  2.  
  3. -- VARIABLES
  4. -- Misc Variables
  5. local flagTeam = false
  6. local Tool = script.Parent
  7. local lastOwnerName = ""
  8. local FlagSpawn = game.Workspace
  9. local allowEquip = true
  10. local flagDropped = false
  11. local flagSetupEvent = game.ReplicatedStorage.BindableEvents.SetupFlags
  12.  
  13. -- Player variables
  14. local chr = Tool.Parent
  15. local hum = chr.Humanoid
  16. local plr = game.Players:GetPlayerFromCharacter(chr)
  17.  
  18. -- Team specific variables
  19. local blueFlagSpawnPosition = Vector3.new(-138.495, 5.145, -166.5)
  20. local redFlagSpawnPosition = Vector3.new(-146.5, 5.006, 125.5)
  21.  
  22.  
  23. -- INIT
  24. -- Checks what flag the script is apart of and sets the flagTeam variable accordingly.
  25. if Tool.Name == "BlueFlag" then
  26.     FlagSpawn = game.Workspace.Flags.Blue.BlueFlagStand
  27. elseif Tool.Name == "RedFlag" then
  28.     FlagSpawn = game.Workspace.Flags.Red.RedFlagStand
  29. else
  30.     return
  31. end
  32.  
  33.  
  34. -- FUNCTIONS
  35. -- Respawns flag
  36. function flagRespawn()
  37.     if Tool.Name == "BlueFlag" then
  38.         local clone = game.ReplicatedStorage.BlueFlag:Clone()
  39.         clone.Parent = game.Workspace.Flags.Blue
  40.         Tool:Destroy()
  41.         clone.Handle.Position = blueFlagSpawnPosition
  42.     elseif Tool.Name == "RedFlag" then
  43.         local clone = game.ReplicatedStorage.RedFlag:Clone()
  44.         clone.Parent = game.Workspace.Flags.Red
  45.         Tool:Destroy()
  46.         clone.Handle.Position = redFlagSpawnPosition
  47.     else
  48.         return
  49.     end
  50. end
  51.  
  52. -- Checks if the flag was removed from the player's backpack.
  53. function flagPlayerInventoryCheck(child)
  54.     if child == Tool then
  55.         flagDropped = true
  56.     else
  57.         return
  58.     end
  59. end
  60.  
  61. -- Right now only checks if the enemy flag was taken by the player.
  62. function flagEquip()
  63.     flagDropped = false
  64.     if lastOwnerName ~= plr.Name then
  65.         game.ReplicatedStorage.FlagTaken:FireAllClients(plr.Name, true)    
  66.         lastOwnerName = plr.Name
  67.        
  68.         if Tool.Name == "RedFlag" and plr.Team.Name == "Blue Team" then
  69.             plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 5
  70.         elseif Tool.Name == "RedFlag" and plr.Team.Name == "Red Team" then
  71.             plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 2
  72.         elseif Tool.Name == "BlueFlag" and plr.Team.Name == "Red Team" then
  73.             plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 5
  74.         elseif Tool.Name == "BlueFlag" and plr.Team.Name == "Blue Team" then
  75.             plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 2
  76.         else
  77.             print("NO! YOU ARE NOT GETTING POINTS, GOOD SIR!")
  78.         end
  79.     else
  80.         return
  81.     end
  82. end
  83.  
  84. -- Checks if the enemy flag was captured by the player.
  85. function flagCapture(touchingPart)
  86.     local Player = game.Players:GetPlayerFromCharacter(touchingPart.Parent)
  87.     if Player and flagDropped == false then
  88.         if Player.Team.Name ~= "Red Team" and Tool.Name == "RedFlag" then
  89.             game.ReplicatedStorage.FlagCaptured:FireAllClients(true)
  90.             Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 10
  91.             flagRespawn()
  92.             return
  93.         elseif Player.Team.Name ~= "Blue Team" and Tool.Name == "BlueFlag" then
  94.             game.ReplicatedStorage.FlagCaptured:FireAllClients(false)
  95.             Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 10
  96.             flagRespawn()
  97.             return
  98.         else
  99.             return
  100.         end
  101.     else
  102.         return
  103.     end
  104. end
  105.  
  106. -- CONNECTIONS
  107. plr.Backpack.ChildRemoved:Connect(flagPlayerInventoryCheck())
  108. Tool.Equipped:Connect(flagEquip())
  109. FlagSpawn.Touched:Connect(flagCapture())
Advertisement
Add Comment
Please, Sign In to add comment