The issue I’m having is that yes, I did add a debounce every time a player captures one of the towns in the game however, the player isn’t able to capture the town again if it gets recaptured by the enemy team/country. I tried setting the debounce to false at a certain condition but still no result.
-- Server script for each town
local module = require(game.ServerScriptService.Modules.TownCaptureModule)
local townhall = script.Parent
local towncapturepart = townhall.TownCapturePart
local debounce = false
towncapturepart.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("SoldierStats") then
if debounce == false and hit.Parent.SoldierStats.NationName.Value == "Yellowstone" and townhall.CurrentCountry.Value == "Yellowstone" then
else
debounce = true
module.CaptureTown(townhall, townhall.TownName.Value, hit.Parent.SoldierStats.FlagID.Value, hit.Parent.SoldierStats.NationName.Value)
--[[
if hit.Parent.SoldierStats.NationName.Value ~= townhall.CurrentCountry.Value then
debounce = false
end
]]--
--[[
towncapturepart.TouchEnded:Connect(function()
debounce = false
end)
]]--
end
end
end)
-- Module script for capturing towns
local module = {}
function module.PlayCaptureSound()
local sound = Instance.new("Sound")
sound.Parent = workspace.Map.Sounds
sound.Name = "CaptureSound"
sound.Volume = 10
sound.SoundId = "rbxassetid://233422074"
sound:Play()
end
function module.AnnounceWinningTeam(team) --// team/country, same thing lol
for i, player in pairs(game.Players:GetPlayers()) do
local playergui = player:FindFirstChild("PlayerGui")
if playergui then
local textlabel = Instance.new("TextLabel")
textlabel.Parent = playergui.Main
textlabel.Name = "WinnerTeamAnnouncementText"
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.Position = UDim2.new(.344, 0, .156, 0)
textlabel.Size = UDim2.new(0, 600, 0, 50)
textlabel.Font = Enum.Font.RobotoMono
textlabel.TextScaled = true
textlabel.TextColor3 = Color3.fromRGB(255, 255, 255)
textlabel.TextStrokeTransparency = 0
textlabel.TextWrapped = true
textlabel.Text = team.." has won the war!"
textlabel.Visible = true
wait(3)
textlabel:Destroy()
end
end
end
function module.CaptureTown(townhall, townname, flagid, currentcountry)
townhall.CurrentCountry.Value = currentcountry
for i, player in pairs(game.Players:GetPlayers()) do
local playergui = player:FindFirstChild("PlayerGui")
if playergui then
local textlabel = Instance.new("TextLabel")
textlabel.Parent = playergui.Main
textlabel.Name = "TownCapturedText"
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.Position = UDim2.new(.344, 0, .1, 0)
textlabel.Size = UDim2.new(0, 600, 0, 50)
textlabel.Font = Enum.Font.RobotoMono
textlabel.TextScaled = true
textlabel.TextColor3 = Color3.fromRGB(255, 255, 255)
textlabel.TextStrokeTransparency = 0
textlabel.TextWrapped = true
textlabel.Text = townname.." has been captured by "..currentcountry
textlabel.Visible = true
module.PlayCaptureSound()
for i, flagpart in pairs(townhall.Flag.Flag:GetChildren()) do
flagpart.TextureID = flagid
end
--[[
for i, town in pairs(workspace.Map:GetDescendants()) do
if town:IsA("Model") then
local currentcountry = town:FindFirstChild("CurrentCountry")
if currentcountry then
if currentcountry.Value == "Yellowstone" then
module.AnnounceWinningTeam("Yellowstone")
elseif currentcountry.Value == "Lakewood" then
module.AnnounceWinningTeam("Lakewood")
else
end
end
end
end
]]--
wait(3)
textlabel:Destroy()
end
end
end
return module