FindFirstChild not working after first time if child has localscript within in it

I’m making a camera console.
When you Access the camera console, it gives you a cameraGUI, and sets a camera CFrame from a folder, which the different cameras are decided with their index.

Before doing this I tested if i could close this GUI and reopen it. If the script that deletes the GUI is a local script or a script, it can delete the GUI. Although If a localScript is included within the child of the clone, it will not work.

This is the code that gives the GUI to the player

local ProximityPrompt = script.Parent:WaitForChild("PartToProx"):WaitForChild("ProximityPrompt")
local Cards = script.Parent:WaitForChild("Cards")

local CameraGUIFolder = script.Parent:WaitForChild("CameraGUIFolder")

function CheckCard(plr)
	for i, v in pairs(Cards:GetChildren()) do
		if plr.Character:FindFirstChild(v.Value) then
			return true
		end
	end
end

function InsertCameraSystemUI(Player)
	local clone = CameraGUIFolder:Clone()
	
	clone.Parent = Player.PlayerGui
	clone.CameraSystemUI.CameraSystemUIScript.Enabled = true
	
end

local bool = true

ProximityPrompt.Triggered:Connect(function(plr)
	if CheckCard(plr) then
		if bool == true then
			bool = false
			
			if not plr.PlayerGui:FindFirstChild("CameraGUIFolder")  then 
				InsertCameraSystemUI(plr)
			end
			
			bool = true
		end
	end
end)

this is the code that removes it from the player, which is in a textbox from the cloned GUI

local UserInputService = game:GetService("UserInputService")

local function Delete()
	script.Parent.Parent.Parent.Parent.Parent:Destroy()
end

script.Parent.MouseButton1Click:Connect(Delete)

If this part is a local script it will not pass the:

if not plr.PlayerGui:FindFirstChild("CameraGUIFolder")  then 
	InsertCameraSystemUI(plr)
end

_
if i try, this, the result is the same

plr.PlayerGui:FindFirstChild("CameraGUIFolder", true)

+ps i also tried to not delete the GUI and just check if it already exists, but i still get the same problem with the findfirstchild not being able to work

What exactly do you mean? If you could, send a video or a few screenshots demonstrating the steps and results of said steps.

This is a bit vague.

1 Like

So the Camera system needs to place a GUI into a player. but i need to check if the GUI already exists so it is not spamable. in other words, so it does not clone more than once into the player.

this is the model
save2

  • The folder is cloned into the playerGUI
  • The localScript removes the Folder

The problem here is that the MainScript. Which inserts the clone and has the FindFirstChild() does not work after the first time.

although if i turn the localscript into a normal script
save4

  • this script does the same as the local script
    everything works perfectly

It’s because deleting things in a LocalScript doesn’t replicate to the server, unless it’s a descendant of the Player’s character. This is the only reason, it’s intentional and cannot be changed, good day.

2 Likes

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