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:
local function buttonPressed(Messed)
local character = Messed.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
--Functions cant be called in if statements
if humanoid and sentinal2 == true then
activetime = true
end
end
finishline.Touched:Connect(partTouched)
button.Touched:Connect(buttonPressed)
while activetime == true do
print("Debug3")
wait(1) timepassed = timepassed + 1
print(timepassed)
end
Full code:
local finishline = script.Parent
local timepassed = 0
local sentinal = true
local button = workspace.startr
local sentinal2 = true
local activetime = false
local function finish()
sentinal = false
print("you finished in" .. timepassed)
if timepassed <= 10 then
print("gold")
elseif timepassed > 10 and timepassed <= 20 then
print("silver")
elseif timepassed > 20 and timepassed <= 30 then
print("bronze")
else
print("try agian")
end
end
local function partTouched(Touched)
local character = Touched.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid and sentinal == true then
end
end
local function buttonPressed(Messed)
local character = Messed.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
--Functions cant be called in if statements
if humanoid and sentinal2 == true then
activetime = true
end
end
finishline.Touched:Connect(partTouched)
button.Touched:Connect(buttonPressed)
while activetime == true do
print("Debug3")
wait(1) timepassed = timepassed + 1
print(timepassed)
end

1 comment
It's not a very good setup, but you could have an if statement wrapped around everything inside of your while loop. Then it will only run your code when the boolean is true..