Hello everyone, I have problem with capture, becouse after capture it should add money only to one team, but it give to everyone...
Here is script(It's script from timer):
Time = 10 owner = script.Parent.CurrentOwner for i = 1, Time do for b, v in pairs(script.Parent.Timer:GetChildren()) do v.Name = "Time: " ..i.. "/" ..Time.. "." wait(1) while wait(5) do for _, owner in ipairs (game.Players:GetPlayers()) do if owner:FindFirstChild("leaderstats") then owner.leaderstats.Cash.Value = owner.leaderstats.Cash.Value + 10 end end end end end Clone = script.RaiderWin:clone() Clone.Parent = game.Workspace Clone.Disabled = false
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") --A BrickColorValue local hasOwner = script.Parent:FindFirstChild("HasCurrentOwner") --A BoolValue. Set to false to reset the owner. local timeToCapture = 10 --in seconds local paymentAmount = 10 --cash to give per payment local paymentEvery = 5 --pay capturing team every 'paymentEvery' seconds local waitBeforeFirstPayment = true --wait 'paymentEvery' seconds after capturing before giving the first payment local noOneCapturedMessage = "Captured by no one." --message to display when no one is capturing/captured the point local previousTeam = nil local timeCounter local currentOwner = nil --BrickColor function UpdateTimer(text) for b, v in ipairs(script.Parent.Timer:GetChildren()) do v.Name = text end end local payoutVersion = 0 function StartPayingOut() --Make sure that if StartPayingOut gets called again, we will exit without payment payoutVersion = payoutVersion + 1 local curVersion = payoutVersion if waitBeforeFirstPayment then wait(paymentEvery) end while currentOwner and curVersion == payoutVersion do --Give payment 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 --This stops captures payoutVersion = 0 --This stops payments 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 --someone else started to capture (or this team left) end UpdateTimer("Captured by the " .. tostring(value) .. " Team") currentOwner = value coroutine.resume(coroutine.create(StartPayingOut)) --Example of how to change the message after 5 seconds if the point is still captured: --wait(5) --if curVersion ~= threadVersion then return end --someone else capturing --UpdateTimer(tostring(value) .. " captured the point at least 5 seconds ago!") threadVersion = 0 --Do this last 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 --cash local paymentPeriod = 5 --seconds 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)