You need to rename "owner" on lines 9-11 to "player", then compare the player's TeamColor to the owner's TeamColor.
Also, you seem to have two different things going on: on line 7 you wait for 1 second, as if you wanted to count from 1 to 10 over 10 seconds, but then you have an infinite while loop on line 8.
If I assume that this script is supposed to give $5 to all players on the team that "CurrentOwner" refers to (assuming CurrentOwner is an ObjectValue that refers to a Team from game.Teams) [edit: and if we assume that it takes time before we actually say that they own this point], then the script can be rewritten like so:
wait()
local owner = script.Parent:WaitForChild("CurrentOwner")
local hasOwner = script.Parent:FindFirstChild("HasCurrentOwner")
local timeToCapture = 10
local paymentAmount = 10
local paymentEvery = 5
local waitBeforeFirstPayment = true
local noOneCapturedMessage = "Captured by no one."
local previousTeam = nil
local timeCounter
local currentOwner = nil
function UpdateTimer(text)
for b, v in ipairs(script.Parent.Timer:GetChildren()) do
v.Name = text
end
end
local payoutVersion = 0
function StartPayingOut()
payoutVersion = payoutVersion + 1
local curVersion = payoutVersion
if waitBeforeFirstPayment then wait(paymentEvery) end
while currentOwner and curVersion == payoutVersion do
for _, player in ipairs(game.Players:GetPlayers()) do
if player.TeamColor == currentOwner and player:FindFirstChild("leaderstats") then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
end
end
wait(paymentEvery)
end
end
local threadVersion = 0
function UpdateOwner(value)
if previousTeam == value then return end
if value == false then
previousTeam = nil
threadVersion = 0
payoutVersion = 0
UpdateTimer(noOneCapturedMessage)
return
elseif value == true then
value = owner.Value
elseif hasOwner and hasOwner.Value == false then
return
end
threadVersion = threadVersion + 1
local curVersion = threadVersion
timeCounter = 0
previousTeam = value
while timeCounter < timeToCapture do
timeCounter = timeCounter + 1
UpdateTimer("Time: " ..timeCounter.. "/" ..timeToCapture.. ".")
wait(1)
if curVersion ~= threadVersion then return end
end
UpdateTimer("Captured by the " .. tostring(value) .. " Team")
currentOwner = value
coroutine.resume(coroutine.create(StartPayingOut))
threadVersion = 0
end
owner.Changed:connect(UpdateOwner)
if hasOwner then hasOwner.Changed:connect(UpdateOwner) end
UpdateTimer(noOneCapturedMessage)
[Edit: I've enhanced the script, in addition to fixing bugs. I've tested it; it should work this time!]
To use this enhanced script, you should probably make use of the "HasCurrentOwner" BoolValue - you'll have to add this yourself (in the same place that CurrentOwner is). The value must be set to true when a player starts capturing it. If they leave before they've captured it, you should set this BoolValue.Value to 'false'. If they leave after they've captured it, keep it at true. You know they've captured it because the Timer will have the text "Captured by the" in it. If the rounds ends, you might set this to 'false' to stop giving the capturing team money.
If you want to turn the "HasCurrentOwner" into a "SomeoneIsCapturing" concept (meaning that if it becomes false, the point remains captured if it is captured, but if it's not yet captured, the progress is reset), then all you have to do to the above script is to delete the line payoutVersion = 0 --This stops payments as well as the line before it, previousTeam = nil.
[Edit2: For your specific needs, use the script below -- put it on the same level as the other scripts, but in its own "Script" object. In the future, consider detailing exactly what you need and what you have.]
local paymentAmount = 10
local paymentPeriod = 5
local owner = script.Parent.CurrentOwner
local neutral = script.Parent.NeutralColor
local payoutVersion = 0
function StartPayingOut()
if owner.Value == neutral.Value then payoutVersion = 0 return end
payoutVersion = payoutVersion + 1
local curVersion = payoutVersion
while curVersion == payoutVersion do
for _, player in ipairs(game.Players:GetPlayers()) do
if player.TeamColor == owner.Value and player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Cash") then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + paymentAmount
end
end
wait(paymentPeriod)
end
end
owner.Changed:connect(StartPayingOut)
2 comments
On line 10, you need to add something to check which team the Player is on. if owner.TeamColor == BrickColor.new("Really red") then ...
But it's like outpost, so if i put one team there they will only can get money? becouse i have 6 teams.