Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
What is your goal, if you don't mind me asking? StateSector 8 — 6y
0
I'm mainly testing a GUI, and the script Conditions? ExtremeRisk 9 — 6y
0
For a GUI? StateSector 8 — 6y
0
pretty much lol ExtremeRisk 9 — 6y
View all comments (5 more)
0
Loading a House?? StateSector 8 — 6y
0
:Remove() is deprecated, use :Destroy() instead User#24403 69 — 6y
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. namespace25 594 — 6y
0
Wrong, :Destroy() locks the parent property while :Remove() does not. Don't use deprecated code, period. User#24403 69 — 6y
0
Try using FindFirstChild or WaitForChild instead of using if object ~= nil Mirzadaswag 110 — 6y

1 answer

Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
6 years ago
Edited 6 years ago

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. :)

0
But you used Remove too. Line 5. namespace25 594 — 6y
0
Oh, whoops. Forgot to edit that part. popeeyy 493 — 6y
Ad

Answer this question