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

Error with while true do loop?

Asked by 9 years ago

I was attempting to activate and deactivate values to run all the scripts in my game but the loop does'nt seem to run, i was looking to see who could help and solve my issue :D THANKS FOR READING

while true do
local Gamestart = workspace.Gamestart.Value
local Intermission = workspace.Intermission.Value
local Inttime = workspace.Inttime.Value
local Resources = workspace.Resources.Value
wait(30)
Intermission = true
Inttime = Inttime -1
if Inttime == 0  then
Intermission = false
Inttime = 30
wait()
Gamestart = true 
if Resources == 0 then
Gamestart = false
local plrs = game.Players:GetPlayers()

for _, player in pairs(plrs) do
    if player.Character and player.Character:FindFirstChild("Humanoid") then
        player.Character.Humanoid.Health = 0
    end
end
end
end
end
0
tauhruiwyaieuyro there are like 13 errors. EzraNehemiah_TF2 3552 — 9y
0
it doesnt show me any errors :/ weird viralmoose 65 — 9y

2 answers

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
9 years ago

You basically had a bunch of the same error in your script. I'll go ahead, and post the fixed script first, then explain it a bit.

Here it is:

while true do
    local Gamestart = workspace.Gamestart
    local Intermission = workspace.Intermission
    local Inttime = workspace.Inttime
    local Resources = workspace.Resources
    Intermission.Value = true
    repeat wait(1) --Repeats following code every second
        if Inttime.Value>0 then
            Inttime.Value=Inttime.Value-1
        end
    until Inttime.Value<=0 --Stop repeating once it hits 0
    if Inttime.Value == 0  then
        Intermission.Value = false
        Inttime.Value = 30
        wait()
        Gamestart.Value = true 
        if Resources.Value == 0 then
            Gamestart.Value = false
            local plrs = game.Players:GetPlayers()
            for _, player in pairs(plrs) do
                if player.Character and player.Character:FindFirstChild("Humanoid") then
                    player.Character.Humanoid.Health = 0
                end
            end
        end
    end
end

So basically, the error you had was that you were defining the Variables: Gamestart, Intermission, Inttime, and Resources, as their Values. When you do this, the script stores the variable as what the value of it was at the time it was called.

Here's an example:

local ValueExample=script.Parent.Value --Let's say this comes out as true
script.Parent.Value=not script.Parent.Value --Changes the value to false
print(ValueExample) --Would print out "true"

This would happen because the value is being changed correctly, but as I already stated, it is storing the value, not the object that you need to access to change it's property.

To fix the above script, we would do this:

local ValueExample=script.Parent --Let's say this is true again
script.Parent.Value=not script.Parent.Value --Changes the value to false
print(ValueExample.Value) --Would print out "false" this time

This time we accessed the object, and were able to change it's property correctly, so the script worked out how we wanted it to.


Anyways, I hope this helped you out a bit. If you have any problems/questions, please leave a comment below :P

0
Thank You! I have a question, wouldnt the loop need to have :Changed function? or will that not be a issue viralmoose 65 — 9y
0
Glad I could help :P . Anyways, I don't think it should be an issue, but if you have any problems with it, let me know, and I'll see what I can do. dyler3 1510 — 9y
0
I still have no errors, but it wont run :/ any ideas? viralmoose 65 — 9y
0
Nevermind, it runs but it wont count down viralmoose 65 — 9y
View all comments (10 more)
0
Just make sure you have all the values correct, and everything. That would be the only problem I would think. Like on line 09, make sure that the value is on 0, or else nothing will happen. dyler3 1510 — 9y
0
Thats not the issue the values number wont go down viralmoose 65 — 9y
0
It goes down once, but whats the proper what to put it to loop down to 0? viralmoose 65 — 9y
0
Oh, ok, i'll update my answer. I assume you want it to count down, 1 each second? dyler3 1510 — 9y
0
Correct! THAT IS THE NUMBER 1 ANSWER :P viralmoose 65 — 9y
0
Lol ok, well I believe it should work now :P dyler3 1510 — 9y
0
Yeah it does, not i need to fix the issue that the text on the gui isnt updating. Scripter Problems. viralmoose 65 — 9y
0
NEW ISSUE, sorry, the gamestart goes to true before the countdown ends, please let me know whats wronge! viralmoose 65 — 9y
0
I'm not sure what would be wrong...make sure it's set to false to begin with. dyler3 1510 — 9y
0
Every thing is false its odd :/ viralmoose 65 — 9y
Ad
Log in to vote
2
Answered by
Scriptree 125
9 years ago

To make it count down you need to make it wait 1 second, and then subtract 1 from the timer value

while true do
        local Gamestart = workspace.Gamestart
        local Intermission = workspace.Intermission
        local Inttime = workspace.Inttime
        local Resources = workspace.Resources
    Intermission.Value = true
        wait()
    while Inttime.Value ~= 0 do -- this will keep counting down till the inttime has reached zero
        wait(1) -- waiting 1 second
            Inttime.Value = Inttime.Value -1 -- subtracting 1 each second
    end
        if Inttime.Value == 0  then
            Intermission.Value = false
            Inttime.Value = 30
            wait()
            Gamestart.Value = true 
            if Resources.Value == 0 then
                    Gamestart.Value = false
                    local plrs = game.Players:GetPlayers()
                    for _, player in pairs(plrs) do
                        if player.Character and player.Character:FindFirstChild("Humanoid") then
                                player.Character.Humanoid.Health = 0
                        end
                    end
            end
    end
end

This should countdown now :D Hope this helped!

0
This should work as well, upvoted :P dyler3 1510 — 9y
0
Thanks :P Scriptree 125 — 9y
0
:3 YUMMY viralmoose 65 — 9y
0
Sorry for the messy code btw, I don't know why it did that lol Scriptree 125 — 9y

Answer this question