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

How do I fix this points script?

Asked by
Ulysies 50
9 years ago

So, I am making a script that when you die you will not get points.. But if you survive you get 10 points. how do I fix this?

for _,v in pairs(game.Players:GetChildren()) do 
            v.PlayerGui.Ament.TextLabel.Text = "Game Ended!"
                end
        wait(3)
        for _,v in pairs(game.Players:GetChildren()) do 
            v.PlayerGui.Ament.TextLabel.Text = "10 Points To Survivers!"
                end                              
        for i, v in pairs(game.Players:GetPlayers())do
            inGame = v:FindFirstChild("InGame")
            if inGame then
                if inGame.Value == true then
                    v.leaderstats.Points.Value = v.leaderstats.Points.Value + 10 --Points Per Round Survived
                end
            end
        end

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

You're re-iterating after your original loop, this is un-needed.


Since the original loop is already a generic for iterating through game.Players then you don't need to make any other loops.


So we can just combine all of your loops(:

--EDIT-- Make another loop to change everyone's text to 'Game Ended' then have a wait() function in between the two loops


for i.v in pairs(game.Players:GetPlayers()) do
    v.PlayerGui.Ament.TextLabel.Text = "Game Ended!"
end
wait(3)
for _,v in pairs(game.Players:GetChildren()) do
    v.PlayerGui.Ament.TextLabel.Text = "10 Points To Survivers!"                      
    local inGame = v:FindFirstChild("InGame")
     --define points here, so you don't have to type it twice
    local points = v.leaderstats.Points
    if inGame then
        if inGame.Value == true then
            points.Value = points.Value + 10
        end
    end
end
1
This won't work as expected, due to the 'wait' command (you'll end up waiting 3 seconds per player). You need two completely separate for loops with the 'wait' command between them - the first loop just makes the message "Game Ended!", the second loop does the rest. chess123mate 5873 — 9y
0
Thanks for pointing that out. Goulstem 8144 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

You need to have a variable that stores whether they've survived or not. It looks like that's what "InGame" is supposed to be. In that case, you need to set its value to false when the player dies (and then reset it to true when a new round starts).

Also, I recommend proper indentation so that it's easier to read:

for _,v in pairs(game.Players:GetChildren()) do 
    v.PlayerGui.Ament.TextLabel.Text = "Game Ended!"
end
wait(3)
for _,v in pairs(game.Players:GetChildren()) do 
    v.PlayerGui.Ament.TextLabel.Text = "10 Points To Survivers!"
    inGame = v:FindFirstChild("InGame")
    if inGame and inGame.Value then
        v.leaderstats.Points.Value = v.leaderstats.Points.Value + 10 --Points Per Round Survived
    end
end

(I also combined the last two for loops and combined the two 'if' statements at the end).

You likely have a function that runs when a player dies. Inside that, just find the "inGame" object for the player (just like you do in the current script) and set its ".Value" to false.

When you start a new round, go through all players's "InGame" values and set them to true.

Answer this question