hey, I tried to use conditionals to break a while true do loop and I was wondering if anyone could help
My Program:
local PhoneCall = math.random(1, 2)
local enabled = true
if PhoneCall == 2 then
print("Phone Triggered")
script.Parent.Enabled = true
while enabled do
script.Parent.Parent.Phone:Play()
wait(0.5)
script.Parent.Parent.Phone:Play()
wait(1)
end
else
print("Phone Not Triggered")
end
script.Parent.Triggered:Connect(function(plr)
enabled = false
end
One thing I noticed about your code is that when PhoneCall is equal to 2 you set script.Parent.Enabled to true even though enabled is already a local variable. Perhaps this is your error?
Edit: Yeah I’m pretty sure that the error is instead of checking and changing script.Parent.Enabled you change a local variable.
I’m guessing the parent is a ProximityPrompt and it seems you forgot to set enabled to true?
local PhoneCall = math.random(1, 2)
local enabled = false
if PhoneCall == 2 then
print("Phone Triggered")
script.Parent.Enabled = true
enabled = true -- this?
while enabled do -- while script.Parent.Enabled do
script.Parent.Parent.Phone:Play()
wait(0.5)
script.Parent.Parent.Phone:Play()
wait(1)
end
else
print("Phone Not Triggered")
end
script.Parent.Triggered:Connect(function(plr)
enabled = false
-- script.Parent.Enabled = false
end