Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Using repeat to find if car = nil isn't working?

So, I'm making an error screen in ScreenGui number 1 and the localscript in ScreenGui number 2. (btw this is at the bottom of the localscript) However, the repeat doesn't work. Code:

repeat
if workspace:FindFirstChild("Car") == nil then
print("car = nil")
wait(1)
if game:GetService("UserInputService").TouchEnabled then
script.Parent.Parent.screen.Frame2:TweenPosition(UDim2.new(0.216, 0,0.162, 0))
elseif game:GetService("UserInputService").KeyboardEnabled then
script.Parent.Parent.screen.Frame2:TweenPosition(UDim2.new(0.344, 0,0.3, 0))
end
end
wait(1)
until workspace:FindFirstChild("Car") == nil

I tried to destroy the car in test mode, but nothing came out, not even the print. There is no error in the output. No print either. Any help will be appreciated.

3 comments

0

you are basically saying (repeat check if car exist until the car exist), so when the car became nil, the repeat loop won't run anymore since it has met the requirements.

0

thanks this works

0

format

1 answer

✓ Accepted answer

As I mentioned in the comment, that won't work due to it meeting the requirements. Instead of doing that, try and make an event that disconnects when you meet the requirements.

local connection

local function event()

if workspace:FindFirstChild("Car") == nil then
 print("car = nil")
  wait(1)
	if game:GetService("UserInputService").TouchEnabled then
   script.Parent.Parent.screen.Frame2:TweenPosition(UDim2.new(0.216, 0,0.162, 0))
   elseif game:GetService("UserInputService").KeyboardEnabled then
   script.Parent.Parent.screen.Frame2:TweenPosition(UDim2.new(0.344, 0,0.3, 0))
connection:Disconnect()
 end
end

end

connection = workspace.Changed:Connect(event)


1 comment

0

oh my please format with indents

This discussion is preserved as it was. New answers, comments, and votes are closed.