Capture point help

Trying to set it so that, the capture point will change everything and then check to see if the players team matches the capture team. And if they match, I want the captured team to gain 250 dragoons. Anyone got any ideas?

local Players = game:GetService("Players")
local Model = script.Parent
local CapturePart = Model:WaitForChild("Capture Part")
local CaptureText = Model:WaitForChild("Team Part"):WaitForChild("BillboardGui"):WaitForChild("TextLabel")
local CaptureSound = Model:WaitForChild("Capture")
local plr = game.Players.LocalPlayer
local team = plr.Team
local cteam = team.Name

if not CaptureSound.IsLoaded then
	CaptureSound.Loaded:Wait()
end

local CaptureSoundLength = CaptureSound.TimeLength

local function ShowCaptureUI(Player, Team, Place)
	if Player:FindFirstChild("PlayerGui"):FindFirstChild("CaptureUI"):FindFirstChild("TextLabel") and 
		Player:FindFirstChild("PlayerGui"):FindFirstChild("CaptureUI"):FindFirstChild("TextLabel2") then
		Player.PlayerGui.CaptureUI.TextLabel.Text = Place .. " Captured by:"
		Player.PlayerGui.CaptureUI.TextLabel2.Text = Team
		Player.PlayerGui.CaptureUI.Enabled = true
	if Team  and
		 cteam == Team then
		while true do
			wait(2)
			Player.Data_Folder.Dragoons.Value += 250
			end
		end
	end
end

local function HideCaptureUI(Player)
	if Player:FindFirstChild("PlayerGui"):FindFirstChild("CaptureUI") then
		Player.PlayerGui.CaptureUI.Enabled = false
	end
end

CapturePart.Touched:Connect(function(Part)
	if Players:GetPlayerFromCharacter(Part.Parent) then
		local Player = Players:GetPlayerFromCharacter(Part.Parent)
		if Player.Team ~= nil and tostring(Player.Team) ~= CaptureText.Text then
			CaptureText.Text = tostring(Player.Team)
			if CaptureSound.Playing == false then
				CaptureSound:Play()
			end
			for i,v in pairs(Players:GetPlayers()) do
				pcall(function()
					ShowCaptureUI(v, tostring(v.Team), "Docks of Kings Landing") --Place name--
					task.wait(CaptureSoundLength)
					HideCaptureUI(v)
				end)
			end
		end
	end
end)

I dont really understand

you want it that capturing a point would give that team 250 points?

whats the issue here?

pretty much yea I just want the capture area to give the whole team and only people on that team 250 points every 2 minutes.

but when I write the script like this it breaks the capture point when I take out

local plr = game.Players.LocalPlayer
local team = plr.Team
local cteam = team.Name

if Team  and
		 cteam == Team then
		while true do
			wait(2)
			Player.Data_Folder.Dragoons.Value += 250

everything else works i just dont know how to add this code in so it gives the points to the team only

You’re adding a while true do, a loop with wait timers
doing so will make every code under that loop not work.

Instead do this:

if Team and cteam == Team then -- assuming cteam and team are both team names
		Player.Data_Folder.Dragoons.Value += 250
	end
end

So changed it to this still doesnt work because of “Team” being nil basically im trying to make cteam(players current team) be equal to the team that captured the point and if they are equal then give the dragoons.

local Players = game:GetService("Players")
local Model = script.Parent
local CapturePart = Model:WaitForChild("Capture Part")
local CaptureText = Model:WaitForChild("Team Part"):WaitForChild("BillboardGui"):WaitForChild("TextLabel")
local CaptureSound = Model:WaitForChild("Capture")
local plr = game.Players.LocalPlayer
local team = plr.Team
local cteam = team.Name

if not CaptureSound.IsLoaded then
	CaptureSound.Loaded:Wait()
end

local CaptureSoundLength = CaptureSound.TimeLength

local function ShowCaptureUI(Player, Team, Place)
	if Player:FindFirstChild("PlayerGui"):FindFirstChild("CaptureUI"):FindFirstChild("TextLabel") and 
		Player:FindFirstChild("PlayerGui"):FindFirstChild("CaptureUI"):FindFirstChild("TextLabel2") then
		Player.PlayerGui.CaptureUI.TextLabel.Text = Place .. " Captured by:"
		Player.PlayerGui.CaptureUI.TextLabel2.Text = Team
		Player.PlayerGui.CaptureUI.Enabled = true
		if Team and cteam == Team then -- assuming cteam and team are both team names
			Player.Data_Folder.Dragoons.Value += 250
		end
	end
end

local function HideCaptureUI(Player)
	if Player:FindFirstChild("PlayerGui"):FindFirstChild("CaptureUI") then
		Player.PlayerGui.CaptureUI.Enabled = false
	end
end

CapturePart.Touched:Connect(function(Part)
	if Players:GetPlayerFromCharacter(Part.Parent) then
		local Player = Players:GetPlayerFromCharacter(Part.Parent)
		if Player.Team ~= nil and tostring(Player.Team) ~= CaptureText.Text then
			CaptureText.Text = tostring(Player.Team)
			if CaptureSound.Playing == false then
				CaptureSound:Play()
			end
			for i,v in pairs(Players:GetPlayers()) do
				pcall(function()
					ShowCaptureUI(v, tostring(v.Team), "Docks of Kings Landing") --Place name--
					task.wait(CaptureSoundLength)
					HideCaptureUI(v)
				end)
			end
		end
	end
end)

because you did tostring(v.team), you tried to make a instance a string
i forgot what it is but its like v.Team.Name