How do I modify this script to fit my needs without screwing it up?
I took this script from one of the capture points in Roblox's pre-made Control Points place template because the place I'm creating has one point to capture. I would like to modify it so I can have only one capture point, which you capture by standing on a block(Not the actual capture point). The script is:
001 | local ControlPoint = script.Parent |
005 | function WaitForChild(parent, instance) |
006 | while parent:FindFirstChild(instance) = = nil do |
007 | parent.ChildAdded:wait() |
009 | return parent:FindFirstChild(instance) |
014 | local MAX_HEIGHT = 300 |
015 | local BILLBOARD_STEPS = 50 |
016 | local TIME_TO_CAPTURE = 10 |
017 | local POINT_AWARD_RATE = 10 |
019 | local TeamsService = Game:GetService( 'Teams' ) |
020 | local PlayersService = Game:GetService( 'Players' ) |
022 | local EventFeed = WaitForChild(game.Workspace, 'EventFeed' ) |
023 | local AddCustomEvent = WaitForChild(EventFeed, 'AddCustomEvent' ) |
024 | local Zone = WaitForChild(ControlPoint, 'Zone' ) |
025 | local billboard = WaitForChild(Zone, 'BillboardGui' ) |
026 | local ScoreText = WaitForChild(billboard, 'TextLabel' ) |
027 | local pad = WaitForChild(ControlPoint, 'Pad' ) |
028 | WaitForChild(pad, 'Mesh' ) |
031 | local ControllingTeamName |
032 | local ControllingTeamColor |
033 | local ControllingTeamPlayerCount |
034 | local TotalPlayerCount |
035 | local PlayersCapturingByTeam |
037 | local PlayersCapturingByTeam |
039 | local ControlPointName = "a control point" |
040 | local radius = (Zone.Size.x + Zone.Size.z) * 0.25 |
043 | local PercentControl = 1 |
045 | function RayIgnoreCheck(hit) |
047 | if hit.Transparency > = 1 or string.lower(string.gsub(hit.Name, 1 , 6 )) = = "effect" or hit:IsDescendantOf(ControlPoint) then |
054 | function RayCast(startPos, vec, rayLength) |
055 | local hitObject, hitPos = game.Workspace:FindPartOnRay(Ray.new(startPos + (vec * . 01 ), vec * rayLength), Handle) |
056 | if hitObject and hitPos then |
057 | local distance = rayLength - (hitPos - startPos).magnitude |
058 | if RayIgnoreCheck(hitObject) and distance > 0 then |
060 | return RayCast(hitPos, vec, distance) |
063 | return hitObject, hitPos |
067 | local RayHit, RayEnd = RayCast(pad.Position, Vector 3. new( 0 , 1 , 0 ), 1000 ) |
068 | local height = math.min(MAX_HEIGHT, (pad.Position - RayEnd).magnitude) |
072 | if ControlPoint:FindFirstChild( 'Padlight' ) then |
073 | padlight = ControlPoint.Padlight |
075 | padlight = pad:Clone() |
077 | padlight.Name = 'Padlight' |
078 | padlight.CanCollide = false |
079 | padlight.Parent = ControlPoint |
082 | if ControlPoint:FindFirstChild( 'Highlight' ) then |
083 | highlight = ControlPoint.Highlight |
085 | highlight = pad:Clone() |
087 | highlight.Name = 'Highlight' |
088 | highlight.CanCollide = false |
089 | highlight.Transparency = . 75 |
090 | highlight.Mesh.Offset = Vector 3. new( 0 , height*. 5 , 0 ) |
091 | highlight.Parent = ControlPoint |
093 | pad.BrickColor = BrickColor.new( "Institutional white" ) |
094 | billboard.Enabled = false |
096 | local function ResizeHighlight(PercentControl, height) |
097 | padlight.Mesh.Scale = pad.Mesh.Scale * Vector 3. new(PercentControl, 1 , PercentControl) * 1.01 |
098 | highlight.Mesh.Scale = pad.Mesh.Scale * Vector 3. new(PercentControl, height * ( 1 / highlight.Size.y), PercentControl) |
101 | ResizeHighlight(PercentControl, height) |
106 | wait(POINT_AWARD_RATE) |
107 | local AwardTeam = nil |
108 | for _, CheckTeam in ipairs (TeamsService:GetTeams()) do |
109 | if CheckTeam.TeamColor = = padlight.BrickColor then |
110 | CheckTeam.Score = CheckTeam.Score + 1 |
111 | ScoreText.TextColor 3 = padlight.BrickColor.Color |
113 | ScoreText.TextStrokeTransparency = 0 |
114 | ScoreText.TextTransparency = 0 |
115 | billboard.StudsOffset = Vector 3. new( 0 , 5 , 0 ) |
116 | billboard.Enabled = true |
117 | for i = 1 , BILLBOARD_STEPS do |
119 | local percent = i / BILLBOARD_STEPS |
120 | billboard.StudsOffset = Vector 3. new( 0 , 5 + (percent * 5 ), 0 ) |
121 | ScoreText.TextStrokeTransparency = percent |
122 | ScoreText.TextTransparency = percent |
124 | billboard.Enabled = false |
132 | local function IsPlayerWithinCaptureRadius(player, capturePosition, captureRadius) |
133 | if player and player.Character ~ = nil then |
134 | local torso = player.Character:FindFirstChild( 'Torso' ) |
135 | local humanoid = player.Character:FindFirstChild( 'Humanoid' ) |
136 | if torso ~ = nil and humanoid~ = nil and humanoid.Health > 0 then |
137 | return torso.Position.y > capturePosition.y and (torso.Position - capturePosition).magnitude < radius |
143 | local function FindTeam(color) |
144 | for _, team in ipairs (PlayersCapturingByTeam) do |
145 | if team.color = = color then |
149 | local team = { color = color, players = { } } |
150 | table.insert(PlayersCapturingByTeam,team) |
159 | PlayersCapturingByTeam = { } |
160 | for _, player in ipairs (PlayersService:GetPlayers()) do |
161 | if IsPlayerWithinCaptureRadius(player, Zone.Position, radius + 2 ) then |
162 | local team = FindTeam(player.TeamColor) |
163 | table.insert(team.players, player.Name) |
167 | ControllingTeamColor = BrickColor.new( 'Medium stone grey' ) |
168 | ControllingTeamPlayerCount = 0 |
170 | for _, team in ipairs (PlayersCapturingByTeam) do |
171 | TotalPlayerCount = TotalPlayerCount + #team.players |
172 | if #team.players > ControllingTeamPlayerCount then |
173 | ControllingTeamColor = team.color |
174 | ControllingTeamPlayerCount = #team.players |
178 | if TotalPlayerCount > = 1 then |
179 | local influence = ControllingTeamPlayerCount - (TotalPlayerCount - ControllingTeamPlayerCount) |
180 | if influence > = 1 then |
181 | if padlight.BrickColor = = ControllingTeamColor then |
182 | if PercentControl < 1 then |
183 | PercentControl = PercentControl + ((RATE / TIME_TO_CAPTURE) * influence) |
186 | PercentControl = PercentControl - ((RATE / TIME_TO_CAPTURE) * influence) |
188 | if PercentControl > 1 then |
190 | elseif PercentControl < 0 then |
191 | padlight.BrickColor = ControllingTeamColor |
192 | highlight.BrickColor = ControllingTeamColor |
194 | ControllingTeamName = "" |
195 | for _, team in ipairs (TeamsService:GetTeams()) do |
196 | if team.TeamColor = = ControllingTeamColor then |
197 | ControllingTeamName = team.Name .. "#" |
200 | if ControllingTeamName ~ = "" then |
201 | AddCustomEvent:Invoke(ControllingTeamName, '[' .. tostring (ControllingTeamColor.Number).. ']' , " captured " ..ControlPointName.. "!" ) |
203 | AddCustomEvent:Invoke(ControlPointName.. " has been captured!" ) |
206 | ResizeHighlight(PercentControl, height) |
How do I modify it without screwing it up?