Hi, I’m making a military game where the purpose of it is that there 2 nations (teams) and each of them have to attack the enemy’s cities and capture them so that the enemy can’t spawn in that specific city and defend it. The capturing system works, however, the progress bar does not. I want people to be able to see the progress bar so that they’ll know how long it’ll take for them to capture it and the enemy to see that their city is being captured. Here’s the code:
-- Server (this is the script for each city)
local module = require(game.ServerScriptService.Modules.TownCaptureModule)
local townhall = script.Parent
--// Town Essentials \\--
local townname = townhall.TownName
local towncapturepart = townhall.TownCapturePart
local debounce = false
local yellowstonecolor = Color3.fromRGB(255, 225, 0)
local lakewoodcolor = Color3.fromRGB(4, 175, 236)
towncapturepart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("SoldierStats") then
-- so this script for the towns of Yellowstone,
--if the player is on the Yellowstone team/nation and the progress bar is at max, then nothing happens.
--If the player is on the Lakewood team/nation (the enemy team), then the progress bar decreases for Yellowstone and as soon as it hits 0, it starts increasing for Lakewood and as soon as it hits 300 (max bar size), then the enemy gains full control of the the town.
if hit.Parent.SoldierStats.NationName.Value == "Yellowstone" then
if capturegui.ProgressBar.Filler.Size == UDim2.new(0, 300, 0, 50) then
elseif capturegui.ProgressBar.Filler.Size < UDim2.new(0, 300, 0, 50) then
if capturegui.ProgressBar.Filler.BackgroundColor3 == yellowstonecolor then
game.ReplicatedStorage.Remotes.Events.IncreaseCapture:FireAllClients(yellowstonecolor)
towncapturepart.TouchEnded:Connect(function()
game.ReplicatedStorage.Remotes.Events.PauseCapture:FireAllClients()
end)
elseif capturegui.ProgressBar.Filler.BackgroundColor3 == lakewoodcolor then
game.ReplicatedStorage.Remotes.Events.DecreaseCapture:FireAllClients(lakewoodcolor)
towncapturepart.TouchEnded:Connect(function()
game.ReplicatedStorage.Remotes.Events.PauseCapture:FireAllClients()
end)
if capturegui.ProgressBar.Filler.Size == UDim2.new(0, 0, 0, 50) then
game.ReplicatedStorage.Remotes.Events.IncreaseCapture:FireAllClients(yellowstonecolor)
towncapturepart.TouchEnded:Connect(function()
game.ReplicatedStorage.Remotes.Events.PauseCapture:FireAllClients()
end)
if capturegui.ProgressBar.Filler.Size == UDim2.new(0, 300, 0, 50) then
module.CaptureTown(townhall, townname.Value, hit.Parent.SoldierStats.FlagID.Value, hit.Parent.SoldierStats.NationName.Value)
end
end
end
end
else
if capturegui.ProgressBar.Filler.Size == UDim2.new(0, 300, 0, 50) then
elseif capturegui.ProgressBar.Filler.Size < UDim2.new(0, 300, 0, 50) then
if capturegui.ProgressBar.Filler.BackgroundColor3 == lakewoodcolor then
game.ReplicatedStorage.Remotes.Events.IncreaseCapture:FireAllClients(lakewoodcolor)
towncapturepart.TouchEnded:Connect(function()
game.ReplicatedStorage.Remotes.Events.PauseCapture:FireAllClients()
end)
elseif capturegui.ProgressBar.Filler.BackgroundColor3 == yellowstonecolor then
game.ReplicatedStorage.Remotes.Events.DecreaseCapture:FireAllClients(yellowstonecolor)
towncapturepart.TouchEnded:Connect(function()
game.ReplicatedStorage.Remotes.Events.PauseCapture:FireAllClients()
end)
if capturegui.ProgressBar.Filler.Size == UDim2.new(0, 0, 0, 50) then
game.ReplicatedStorage.Remotes.Events.IncreaseCapture:FireAllClients(lakewoodcolor)
towncapturepart.TouchEnded:Connect(function()
game.ReplicatedStorage.Remotes.Events.PauseCapture:FireAllClients()
end)
if capturegui.ProgressBar.Filler.Size == UDim2.new(0, 300, 0, 50) then
module.CaptureTown(townhall, townname.Value, hit.Parent.SoldierStats.FlagID.Value, hit.Parent.SoldierStats.NationName.Value)
end
end
end
end
end
end
end)
-- ModuleScript (this is the module for capturing towns)
local module = {}
function module.CaptureTown(townhall, townname, flagid, currentcountry)
townhall.CurrentCountry.Value = currentcountry
for i, player in pairs(game.Players:GetPlayers()) do
player.PlayerGui.Main.TownCapturedText.Visible = true
player.PlayerGui.Main.TownCapturedText.Text = townname.." has been captured by "..currentcountry
wait(3)
player.PlayerGui.Main.TownCapturedText.Visible = false
player.PlayerGui.Main.TownCapturedText.Text = ""
end
for i, flagpart in pairs(townhall.Flag.Flag:GetChildren()) do
flagpart.TextureID = flagid
end
end
return module
-- Client (this is the LocalScript for the progress bar)
local progressbar = script.Parent
local filler = progressbar.Filler
game.ReplicatedStorage.Remotes.Events.IncreaseCapture.OnClientEvent:Connect(function(countrycolor)
filler.BackgroundColor3 = countrycolor
filler:TweenSize(UDim2.new(0, 300, 0, 50), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 30)
end)
game.ReplicatedStorage.Remotes.Events.DecreaseCapture.OnClientEvent:Connect(function(countrycolor)
filler.BackgroundColor3 = countrycolor
filler:TweenSize(UDim2.new(0, 0, 0, 50), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 30)
end)
game.ReplicatedStorage.Remotes.Events.PauseCapture.OnClientEvent:Connect(function()
filler:TweenSize(filler.Size, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0, true)
end)