Advertisement
HowToRoblox

CTPGuiHandler

Dec 2nd, 2022
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. local rs = game.ReplicatedStorage:WaitForChild("CTPReplicatedStorage")
  2. local config = require(rs:WaitForChild("CONFIGURATION"))
  3. local status = rs:WaitForChild("STATUS")
  4.  
  5. local statusText = script.Parent:WaitForChild("StatusText")
  6. local teamsFrame = script.Parent:WaitForChild("TeamsFrame")
  7. teamsFrame.Visible = false
  8. local captureBar = script.Parent:WaitForChild("CaptureProgressBar")
  9. captureBar.Visible = false
  10.  
  11. local client = game.Players.LocalPlayer
  12.  
  13.  
  14. function updateStatus()
  15.     if not client:FindFirstChild("FAILED TO LOAD DATA") then
  16.         statusText.Text = status.Value
  17.     else
  18.         statusText.Text = "Your data did not load successfully. Rejoin to fix this issue."
  19.     end
  20. end
  21.  
  22. updateStatus()
  23. status:GetPropertyChangedSignal("Value"):Connect(updateStatus)
  24.  
  25.  
  26. rs.ChildAdded:Connect(function(child)
  27.    
  28.     if child.Name == "SCORES" then
  29.         local team1Score = child:WaitForChild("TEAM 1 SCORE")
  30.         local team2Score = child:WaitForChild("TEAM 2 SCORE")
  31.        
  32.         local plrTeam = client.Team
  33.         teamsFrame.Team1Frame.BackgroundColor3 = plrTeam.TeamColor.Color
  34.        
  35.         if plrTeam == config.Team1 then
  36.             teamsFrame.Team2Frame.BackgroundColor3 = config.Team2.TeamColor.Color
  37.            
  38.             teamsFrame.Team1Frame.Points.Text = team1Score.Value
  39.             teamsFrame.Team2Frame.Points.Text = team2Score.Value
  40.            
  41.         elseif plrTeam == config.Team2 then
  42.             teamsFrame.Team2Frame.BackgroundColor3 = config.Team1.TeamColor.Color
  43.            
  44.             teamsFrame.Team1Frame.Points.Text = team2Score.Value
  45.             teamsFrame.Team2Frame.Points.Text = team1Score.Value
  46.         end
  47.        
  48.         team1Score:GetPropertyChangedSignal("Value"):Connect(function()
  49.             if plrTeam == config.Team1 then
  50.                 teamsFrame.Team1Frame.Points.Text = team1Score.Value
  51.             else
  52.                 teamsFrame.Team2Frame.Points.Text = team1Score.Value
  53.             end
  54.         end)
  55.         team2Score:GetPropertyChangedSignal("Value"):Connect(function()
  56.             if plrTeam == config.Team2 then
  57.                 teamsFrame.Team1Frame.Points.Text = team2Score.Value
  58.             else
  59.                 teamsFrame.Team2Frame.Points.Text = team2Score.Value
  60.             end
  61.         end)
  62.        
  63.         teamsFrame.Visible = true  
  64.        
  65.        
  66.         local contestedValue = child:FindFirstChildOfClass("NumberValue")
  67.         while not contestedValue do
  68.             contestedValue = child:FindFirstChildOfClass("NumberValue")
  69.         end
  70.        
  71.         contestedValue.Changed:Connect(function()
  72.             local contestingTeam = config[contestedValue.Name]
  73.             if contestingTeam then
  74.                 local timeContested = contestedValue.Value
  75.                
  76.                 local barScale = timeContested / config.TimeToCapture
  77.                 if barScale <= 1 then
  78.                     captureBar.Bar.BackgroundColor3 = contestingTeam.TeamColor.Color
  79.                     captureBar.Bar.Size = UDim2.new(barScale, 0, captureBar.Bar.Size.Y.Scale, 0)
  80.                     captureBar.Visible = true
  81.                 else
  82.                     captureBar.Visible = false
  83.                 end
  84.             else
  85.                 captureBar.Visible = false
  86.             end
  87.         end)
  88.        
  89.        
  90.         child.Destroying:Connect(function()
  91.             teamsFrame.Visible = false
  92.             captureBar.Visible = false
  93.         end)
  94.     end
  95. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement