Stopping Multiple Gui's From Showing Up

I have some code to make a gui pop up when a player steps on a certain brick, however when they move a new gui pops up how do I make it so it won’t pop up if one is already shown on the screen?

Script
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
end
end)

3 Likes

Check if any existing frames are visible, and if not then show.

1 Like

Have the button check the PlayerGui for the GUI that is trying to clone. If it is there it will not display multiple ones.

1 Like

I did this but it said there was an error

script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
		if StarterGui.ColorBlindTest.Enabled = false then
			if StarterGui.ColorBlindLockScreenTest.Enabled = false then
		
	game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
    end
end)
1 Like

As everyone said above, add a check to see if there are any existing GUIs there.

This can be done by simply searching inside the player’s PlayerGui to see if there is the gui, and if there isn’t then it will fire the remote event;

  • EDIT; It seems your remote event enables the GUI instead of cloning a gui so make the check see if the GUI is enabled
Script that checks for GUI
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr then
                if not plr:WaitForChild("PlayerGui"):FindFirstChild("GUINAME") then -- Checks if there's a gui named "GUINAME" in the player gui and if there isn't it will move to the next line
                    game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
                end
        end
end)
Script that checks for GUI Visibility
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr then
                if not plr:WaitForChild("PlayerGui"):FindFirstChild("GUINAME").Enabled == true then -- Checks if there's a gui named "GUINAME" in the player gui that is enabled and if there isn't it will move to the next line
                    game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
                end
        end
end)

But on the sides there are a shop and teleporting gui

Okay so from my understanding, you have a script in a part, which fires a remote to a player?

I just saw your above post (MY BAD ;-;);

-- Your script
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
		if StarterGui.ColorBlindTest.Enabled = false then
			if StarterGui.ColorBlindLockScreenTest.Enabled = false then
		
	game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
    end
end)
  • This is throwing an error because if statements need a double equals instead of one.
  • You need the ends to close the if statements.
  • Also it’s checking the startergui not the playergui.
-- Fixed script
script.Parent.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
		if plr:WaitForChild("PlayerGui").ColorBlindTest.Enabled == false then
			if plr:WaitForChild("PlayerGui").ColorBlindLockScreenTest.Enabled == false then
		
	game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
end 
end
    end
end)
1 Like

So I have a part and when the player steps on it then a Gui shows up. But when they move around while the gui is still showing another gui shows up. The remote event is in the part so when a player touches the part it makes the gui show up.

It’s still not working and no errors are coming up, here’s what I have.

In the workspace under a brick I have a script that shows the following
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if plr:WaitForChild(“PlayerGui”).ColorBlindTest.Enabled == false then
if plr:WaitForChild(“PlayerGui”).ColorBlindLockScreenTest.Enabled == false then

	game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
end 
end
    end
end)

In the StarterGui I have a screen gui named ColorBlindTest under that there’s a local script saying

game.ReplicatedStorage.RemoteEvent2.OnClientEvent:Connect(function()

script.Parent.Enabled = true

end)

Also under the ColorBlindTestGui I have a text button with the following code
script.Parent.MouseButton1Click:Connect(function()

game.Players.LocalPlayer.PlayerGui.ColorBlindTest.Enabled = false

game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.Enabled = true

end)

In another ScreenGui named ColorBlindLockScreenTest I have the following code

script.Parent.MouseButton1Click:Connect(function()

 game.Players.LocalPlayer.PlayerGui.ColorBlindTest.Enabled = false

 game.Players.LocalPlayer.PlayerGui.ColorBlindLockScreenTest.Enabled = true

end)

Instead of GetPlayerFromCharacter() try searching for the player in game.Players

Instead of;

local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then

try

local plr = game.Players:FindFirstChild(hit.Parent.Name)
if plr then

Also, make sure that all the gui’s Enabled property in StarterGui are set to false.

1 Like

It still didn’t work and the gui’s Enabled property in StarterGui are set to false

Maybe add some print functions to see what’s not firing;

script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
print(plr.Name.." touched the part B)")
if plr:WaitForChild(“PlayerGui”).ColorBlindTest.Enabled == false then
print("ColorBlindTest is not enabled")
if plr:WaitForChild(“PlayerGui”).ColorBlindLockScreenTest.Enabled == false then
print("ColorBlindLockScreenTest is not enabled")
	game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
print("Fired remote event")
end 
end
    end
end)
1 Like

All of the functions are firing

Hmmm that means it can’t be the script in the workspace’s fault so maybe it has to be something to do with the OnClientEvent() event.

maybe add a wait for the RemoteEvent2 in replicated storage and add some prints to see if the client event is firing

game.ReplicatedStorage:WaitForChild("RemoteEvent2").OnClientEvent(function()
print("Client Event Fired")

script.Parent.Enabled = true

print("ColorBlindTest is enabled")
end)
1 Like

Inside the ColorBlindTest screengui, as that’s where the OnClientEvent() event is going to be fired.

The words are printed in the outbox and they showed up twice because I moved around on the brick, so does that mean there’s something wrong with the code in the platform?

Can you clarify? What do you mean by “words” and “platform”?

If the platform you’re referencing is the brick then it’s fine; the print() function is being fired because everytime the brick is touched is fires the touch event. If you don’t want this you can add a debounce/cooldown to the touched event in the brick’s script.

local DebounceCooldown = 5
local Debounce = false

script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if Debounce == false then -- Checks if debounce is false
Debounce = true -- Sets debounce to true so that the rest of the code isn't being executed again
print(plr.Name.." touched the part B)")
if plr:WaitForChild(“PlayerGui”).ColorBlindTest.Enabled == false then
print("ColorBlindTest is not enabled")
if plr:WaitForChild(“PlayerGui”).ColorBlindLockScreenTest.Enabled == false then
print("ColorBlindLockScreenTest is not enabled")
	game.ReplicatedStorage.RemoteEvent2:FireClient(plr)
print("Fired remote event")
    end 
    end
wait(DebounceCooldown) -- Waits how many seconds the cooldown is
Debounce = false -- Sets debounce to false so that the code can be executed again
    end
end)
1 Like

So an error occurs saying that on the very last line it expected end to close the function.

> 21:18:07.534 - Workspace.CBBrick.Make Test Show On Hit:21: Expected 'end' (to close 'function' at line 4), got <eof>

It means you have missed an end somewhere in your code. Format it properly and then you’ll be able to solve the issue.