local capturer local flagColor = flag.BrickColor local capturers = 0 defenders = 0 flag.Transparency = 0 for _, player in pairs(players:GetPlayers()) do local character = player.Character if not character then return end local humanoidRootPart = character:FindFirstChild('HumanoidRootPart') if not humanoidRootPart then return end local humanoid = character:FindFirstChild('Humanoid') local distance = (humanoidRootPart.CFrame.p - flag.CFrame.p).magnitude if distance < range and humanoid.Health > 0 then if firstColor == nil then firstColor = player.TeamColor end if firstColor ~= nil then if player.TeamColor == firstColor then if player.TeamColor ~= flagColor then capturers = capturers + 1 giveCapturing(player) end else defenders = defenders + 1 giveCapturing(player) end end capturer = player else giveCapturing(player) end end if capturers > 0 then if defenders == 0 then flag.Transparency = 0 local ratio = 2.5 if not reset then if percent < 100 then percent = percent + (capturers/ratio) else percent = 100 reset = true end elseif reset then if percent > 0 then percent = percent - (capturers/ratio) else local color = flag.BrickColor percent = 0 reset = false flag.BrickColor = firstColor firstColor = nil for _, player in pairs(players:GetPlayers()) do if player.TeamColor == flag.BrickColor then local character = player.Character if not character then return end local humanoidRootPart = character:FindFirstChild('HumanoidRootPart') if not humanoidRootPart then return end local humanoid = character:FindFirstChild('Humanoid') local distance = (humanoidRootPart.CFrame.p - flag.CFrame.p).magnitude if player:FindFirstChild('Capturing') then local capturing = player.Capturing debris:AddItem(capturing, 1) end if distance < range and humanoid.Health > 0 then print(1) -- Players who have captured it end end end end end else flag.Transparency = 0.5 end else firstColor = nil if percent > 0 then percent = percent - 1 reset = false else reset = false end end flag.CFrame = defaultCFrame - Vector3.new(0, (percent/100)*(pole.Size.Y - flag.Size.Y), 0) if configuration.BLUE_SCORE == configuration.KOTH_SCORE or configuration.RED_SCORE == configuration.KOTH_SCORE then timeManager:End() end end
So it’s basically a flag that players stand near to claim for their team. This is NOT my own code!! It’s taken from a really old copy of one of the original Paintball games. I have made small edits around the place to get it to work, but since this is an old script (around 2013-2014) I was wondering how I could go about making this a LOT cleaner and easier to read. I was thinking of firstly just chucking all the variables in a Module somewhere in RepStorage, so I can easily change the certain values around without having to find the script in multiple maps and change it all.
Trying to break it down to the bare bones would be like
- If player gets within a certain range of the flag and they are still alive (no dead body parts flying around the map) then the flag starts to lower and become ‘captured’
- If somebody else from your team comes within the capture range, then it speeds up the capture rate.
- If a player from the opposing team enters while you are trying to capture, the flag will stop, and won’t move until one the players has left the area.
- If 2 red players and 1 blue player are in the area, the flag will go down for the red team.
- Once flag has gone to the bottom of the pole and then back up to the top, it has become captured and changes color to show what team currently has the flag ‘captured’
Not sure if I am missing any points, but that’s kinda the general breakdown. I’m sure I could probably use functions a lot more too? Like checkPlayerDistance() checkIfAlive() checkDefenders(), or something like that etc. to kinda break down the code a lil more