Touching part only opening ScreenGui once

Hello, i am trying to make it so when you touch a certain part a rebirth screen pops up, it works fine but only works once, if I close the screen and try to open it again by touching the part it simply doesn’t work , there are no errors in the console so I don’t know why this is happening.
Script inside the part:

	if hit.Parent:FindFirstChild("Humanoid") then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		plr.PlayerGui.rebirthscreen.Enabled = true

cant you just destroy it and when you touch the part again it gives a new one?

local DB = true

	if DB then
		DB = false
		if hit:FindFirstAncestorWhichIsA("Model") then
			local Character :Model = hit:FindFirstAncestorWhichIsA("Model")
			if Character:FindFirstChildWhichIsA("Humanoid") then
				local plr = game.Players:GetPlayerFromCharacter(Character)
				plr.PlayerGui.RebirthScreen.Enabled = true
		DB = true
````Preformatted text`

Prety Much bit different to find the character and added some details mait
firstime helping someone in devforum .-.

This looks like you’re opening the GUI on the server, which you should never do.

You’re probably closing the GUI on the client, so now the server and client have a disconnect where the server thinks the GUI is enabled while the client things it is disabled. When you try to enable it again on the server, it sees no difference and so there is no change to replicate to the client.

Either send a remote to the client on touch, or move the touch listener to the client.

I mean you can but what i see his trying to keep everything simple

1 Like

Hi, here you go.

-- This is a server script
local OpenGuiRemote = game.ReplicatedStorage.OpenGuiRemote -- This is your remote
local GuiParts = { -- This is a table with different Parts
	PartA = workspace.GuiPartA, -- This part opens GuiA
	PartB = workspace.GuiPartB, -- This part opens GuiB
local GuiDebounce = {} -- Empty dictionary, we insert the playerName when they touch the GuiPart, and remove it after X amount of time

for _, Part in GuiParts do -- For each GuiPart create a touched event
	Part.Touched:Connect(function(Hit) -- On touched, define what touched the part
		local Character = Hit.Parent -- Define character
		local Humanoid = Character:FindFirstChildOfClass("Humanoid") -- If character has a humanoid, then we know it is a character
		if not Humanoid or Humanoid.Health == 0 then return end -- If not humanoid or humanoid is dead return end
		local Player = game.Players:GetPlayerFromCharacter(Character) -- Get player from character
		if not Player then return end -- If player was not found return end
		if GuiDebounce[Player.Name] then return end -- If GuiDebounce then return end
		GuiDebounce[Player.Name] = true -- Add name to dictionary, so we cannot fire it twice
		OpenGuiRemote:FireClient(Player, Part.Name) -- Fire the player the signal that they should open the Gui. Which gui? Well let us send the Part.Name aswell to define that. So if they touch PartA we tell client to open GuiA
		task.wait(1) -- Wait before that player can open that gui again
		GuiDebounce[Player.Name] = nil -- remove name to dictionary, so we can fire it again
-- This is a local script
-- On the client we have to use GetService to achieve services & also have to wait for parts to spawn in
local OpenGuiRemote = game:GetService("ReplicatedStorage"):WaitForChild("OpenGuiRemote") -- This is your remote
	if PartName == "GuiPartA" then
		print("Open Gui A")
	elseif PartName == "GuiPartB" then
		print("Open Gui B")
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.