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

Nesting While loops?

Asked by
haillin 60
11 years ago

Greetings fellow Robloxians... I've been writing this script that does as follows:

(Player stands on brick the brick changes color if the players health isn't 100 it heals him and once he leaves the pad it changes back to the original color... )

(THE PROBLEM- The problem I'm having is that on the marked line bellow I can't figure out how to have the player heal only while he is standing on the pad.. If he moves he no longer receives healing. I tried to nest the while loop but had no luck. I've did some researching and articles say you nest while loops by:

while(condition) do while(condition) do statement(s) end statement(s) end

However I had no luck with that so I tried to use the 'and' identifier and once more I had no luck. I'd appreciate if a trained eye can view my code and tell me what I'm doing wrong, thank you very much in advance.

001db=false
002function heal(player)
003 
004if db then return end
005db=true
006 
007 
008local h = player.Parent:FindFirstChild("Humanoid")
009 
010if h~= nil and h:FindFirstChild("Value")== nil then
011 
012local brick=script.Parent  
013 
014character=h.Parent
015 
View all 133 lines...

2 answers

Log in to vote
0
Answered by 11 years ago

As with the other reply, I am at school so I can't test but I hope it works:

01local heal = 4
02local brick = script.Parent
03 
04brick.Touched:connect(function(obj)
05    local on = false
06 
07    for i = 1, 10 do
08        wait(.1)
09        brick.Transparency = i/10
10    end
11 
12    brick.BrickColor = BrickColor.new("Really red") wait(.1)
13 
14    for i = 9, 0, -1 do
15        wait(.1)
View all 37 lines...
Ad
Log in to vote
-1
Answered by 11 years ago

Hey I am not 100% sure as I made this in school and I am not able to test it out on studio so if this works I am glad that it helped if not then mind telling me the problem?

01--[[
02    This is not yet tested just made off a guess so if it works your welcome if not tell me what the error is
03]]
04 
05local part -- Make sure to say what is this part
06local on = false
07 
08part.Touched:connect(function(obj)
09    if(obj ~= nil)then
10        if (obj:FindFirstChild("Humanoid") ~= nil) then
11            on = true
12            CheckIsOn(obj, 1)
13        end
14        repeat wait() until obj == nil
15        on = false
View all 31 lines...

Answer this question