How to change a variable inside a function to activate a while true do loop?
Hello! I have made few posts on this but here are the basics of this issue I'm trying to learn from.
Basically I'm trying to get a boolean variable to turn true so that a while true loop can activate.
It would help me greatly to tell me what the mistake is so I won't do it again. :)
Trouble code:
01 | local function buttonPressed(Messed) |
02 | local character = Messed.Parent |
03 | local humanoid = character:FindFirstChildWhichIsA( "Humanoid" ) |
05 | if humanoid and sentinal 2 = = true then |
12 | finishline.Touched:Connect(partTouched) |
13 | button.Touched:Connect(buttonPressed) |
15 | while activetime = = true do |
17 | wait( 1 ) timepassed = timepassed + 1 |
Full code:
01 | local finishline = script.Parent |
05 | local button = workspace.startr |
08 | local activetime = false |
10 | local function finish() |
12 | print ( "you finished in" .. timepassed) |
13 | if timepassed < = 10 then |
16 | elseif timepassed > 10 and timepassed < = 20 then |
19 | elseif timepassed > 20 and timepassed < = 30 then |
26 | local function partTouched(Touched) |
28 | local character = Touched.Parent |
29 | local humanoid = character:FindFirstChildWhichIsA( "Humanoid" ) |
30 | if humanoid and sentinal = = true then |
36 | local function buttonPressed(Messed) |
37 | local character = Messed.Parent |
38 | local humanoid = character:FindFirstChildWhichIsA( "Humanoid" ) |
40 | if humanoid and sentinal 2 = = true then |
47 | finishline.Touched:Connect(partTouched) |
48 | button.Touched:Connect(buttonPressed) |
50 | while activetime = = true do |
52 | wait( 1 ) timepassed = timepassed + 1 |