Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me with capture which give to one team money?

Asked by 8 years ago

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 
0
On line 10, you need to add something to check which team the Player is on. if owner.TeamColor == BrickColor.new("Really red") then ... Validark 1580 — 8y
0
But it's like outpost, so if i put one team there they will only can get money? becouse i have 6 teams. DevKarolus1 70 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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)
0
So the idea is that you want it to take 10 seconds to capture the outpost? If so, what modifies the 'CurrentOwner' value? Also, what's the purpose of lines 17+ in your script? chess123mate 5873 — 8y
0
Edited chess123mate 5873 — 8y
0
Umm... sometimes work, but sometimes don't... Can you check it? Maybe somewhere is mistake? DevKarolus1 70 — 8y
0
You're right, I had a few bugs. I enhanced the script - read the text below the script for recommended instructions (and feel free to edit the values of the variables before line 9). You don't have to use the 'HasCurrentOwner' if you don't want. chess123mate 5873 — 8y
View all comments (10 more)
0
Now don't work... Maybe i'll give you link to that capture system and you will see in full post, becouse it's not my... Link:http://www.roblox.com/Ombre-Empire-Capture-System-item?id=107171716 DevKarolus1 70 — 8y
0
Wow you have a mess... anyway, see the bottom of my answer, Edit2 and the bottom script. chess123mate 5873 — 8y
0
Ugh... i have another problem, becouse i want use outposts to berezaa tycoon kit, but there is a FilteringEnabled, so player can't use that cash from outpost to buy something in tycoon. DevKarolus1 70 — 8y
0
To solve that, you should just create a RemoteFunction named "Purchase(whatever)"; the server then spends the money (if there's enough to purchase 'whatever') and then spawns the desired object(s) chess123mate 5873 — 8y
0
Where i should add that remotefunction? I think to that function should be script? DevKarolus1 70 — 8y
0
I saw and i understand nothing... I don't know where add script and where i should make that RemoteFunction and where put script and which script should i use... It's ****** hard... DevKarolus1 70 — 8y
0
So can you help me solve it? DevKarolus1 70 — 8y
0
No chess123mate 5873 — 8y
Ad

Answer this question