Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FlagScript
- -- VARIABLES
- -- Misc Variables
- local flagTeam = false
- local Tool = script.Parent
- local lastOwnerName = ""
- local FlagSpawn = game.Workspace
- local allowEquip = true
- local flagDropped = false
- local flagSetupEvent = game.ReplicatedStorage.BindableEvents.SetupFlags
- -- Player variables
- local chr = Tool.Parent
- local hum = chr.Humanoid
- local plr = game.Players:GetPlayerFromCharacter(chr)
- -- Team specific variables
- local blueFlagSpawnPosition = Vector3.new(-138.495, 5.145, -166.5)
- local redFlagSpawnPosition = Vector3.new(-146.5, 5.006, 125.5)
- -- INIT
- -- Checks what flag the script is apart of and sets the flagTeam variable accordingly.
- if Tool.Name == "BlueFlag" then
- FlagSpawn = game.Workspace.Flags.Blue.BlueFlagStand
- elseif Tool.Name == "RedFlag" then
- FlagSpawn = game.Workspace.Flags.Red.RedFlagStand
- else
- return
- end
- -- FUNCTIONS
- -- Respawns flag
- function flagRespawn()
- if Tool.Name == "BlueFlag" then
- local clone = game.ReplicatedStorage.BlueFlag:Clone()
- clone.Parent = game.Workspace.Flags.Blue
- Tool:Destroy()
- clone.Handle.Position = blueFlagSpawnPosition
- elseif Tool.Name == "RedFlag" then
- local clone = game.ReplicatedStorage.RedFlag:Clone()
- clone.Parent = game.Workspace.Flags.Red
- Tool:Destroy()
- clone.Handle.Position = redFlagSpawnPosition
- else
- return
- end
- end
- -- Checks if the flag was removed from the player's backpack.
- function flagPlayerInventoryCheck(child)
- if child == Tool then
- flagDropped = true
- else
- return
- end
- end
- -- Right now only checks if the enemy flag was taken by the player.
- function flagEquip()
- flagDropped = false
- if lastOwnerName ~= plr.Name then
- game.ReplicatedStorage.FlagTaken:FireAllClients(plr.Name, true)
- lastOwnerName = plr.Name
- if Tool.Name == "RedFlag" and plr.Team.Name == "Blue Team" then
- plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 5
- elseif Tool.Name == "RedFlag" and plr.Team.Name == "Red Team" then
- plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 2
- elseif Tool.Name == "BlueFlag" and plr.Team.Name == "Red Team" then
- plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 5
- elseif Tool.Name == "BlueFlag" and plr.Team.Name == "Blue Team" then
- plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 2
- else
- print("NO! YOU ARE NOT GETTING POINTS, GOOD SIR!")
- end
- else
- return
- end
- end
- -- Checks if the enemy flag was captured by the player.
- function flagCapture(touchingPart)
- local Player = game.Players:GetPlayerFromCharacter(touchingPart.Parent)
- if Player and flagDropped == false then
- if Player.Team.Name ~= "Red Team" and Tool.Name == "RedFlag" then
- game.ReplicatedStorage.FlagCaptured:FireAllClients(true)
- Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 10
- flagRespawn()
- return
- elseif Player.Team.Name ~= "Blue Team" and Tool.Name == "BlueFlag" then
- game.ReplicatedStorage.FlagCaptured:FireAllClients(false)
- Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 10
- flagRespawn()
- return
- else
- return
- end
- else
- return
- end
- end
- -- CONNECTIONS
- plr.Backpack.ChildRemoved:Connect(flagPlayerInventoryCheck())
- Tool.Equipped:Connect(flagEquip())
- FlagSpawn.Touched:Connect(flagCapture())
Advertisement
Add Comment
Please, Sign In to add comment