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

The 'else' condition is not working when there is no remote event?

Basically, I'm making a GUI with a button, when you click it, it checks if there is a RemoteEvent present, which if it does, it works, but the else statement doesn't seem to work.

script.Parent.MouseButton1Click:Connect(function()
	if game.ReplicatedStorage.gui_instance ~= nil then
		game.ReplicatedStorage.gui_instance:FireServer()
		script.Parent.Parent.Parent.Frame.Visible = true
		script.Parent.Parent.Parent.Frame1:Remove()
		game.StarterGui:SetCore("SendNotification",{Title="Success!"; Text="GUI Attached!"})
	else
		game.StarterGui:SetCore("SendNotification",{Title="Error"; Text="RemoteEvent not found!"})
		wait(10)
		script.Parent.Parent.Parent.Parent.ScreenGui:Remove()
	end
end)

9 comments

0

What is your goal, if you don't mind me asking?

0

I'm mainly testing a GUI, and the script Conditions?

0

For a GUI?

0

pretty much lol

0

Loading a House??

0

:Remove() is deprecated, use :Destroy() instead

0

It's really not need tho, Remove works just the same and has not defects. They just replaced it with a fancy work. Destroy.

0

Wrong, :Destroy() locks the parent property while :Remove() does not. Don't use deprecated code, period.

0

Try using FindFirstChild or WaitForChild instead of using if object ~= nil

1 answer

✓ Accepted answer

First of all, you should not be using :Remove, use :Destroy instead. Also, your script will error out and stop if it is nil, so you should be using :FindFirstChild. Console would have also helped in this case so be sure to have it open.

script.Parent.MouseButton1Click:Connect(function()
    if game.ReplicatedStorage:FindFirstChild("gui_instance") then
        game.ReplicatedStorage.gui_instance:FireServer()
        script.Parent.Parent.Parent.Frame.Visible = true
        script.Parent.Parent.Parent.Frame1:Destroy()
        game.StarterGui:SetCore("SendNotification",{Title="Success!"; Text="GUI Attached!"})
    else
        game.StarterGui:SetCore("SendNotification",{Title="Error"; Text="RemoteEvent not found!"})
        wait(10)
        script.Parent.Parent.Parent.Parent.ScreenGui:Destroy()
    end
end)

The code above should work, if you have any issues let me know. :)

2 comments

0

But you used Remove too. Line 5.

0

Oh, whoops. Forgot to edit that part.

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