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

Help with :Clone()?

Why won't the Guis clone in to the PlayersGui folder(Line 12)? I have no errors at all.

The script is setup like this.

while wait() do
	for _,Player in pairs (game.Players:GetChildren()) do
-------------------------------------------------------
		local Part = script.Parent
		local Character = Player.Character
		local Distance = (Character.Torso.Position - Part.Position).magnitude
		local HasGui = false
		-------------------------------------------------------	
		print(Distance)
			if Distance < 4 then
				CopyGuis = coroutine.create(function()
				for _,Guis in pairs (Part.GuiFolder:GetChildren())do
					CopiedGuis = Guis:Clone()
						CopiedGuis.Parent = Player.PlayerGui
			FoundCopyGuis = Player.PlayerGui:FindFirstChild(CopiedGui)
				if FoundCopyGuis then
						coroutine.yield(CopyGuis)
					print("This player has all guis")
				else
					coroutine.resume(CopyGuis)				
													
	end
		end
			end)
				end
					end
						end



	

1 comment

1

Please tab correct

1 answer

✓ Accepted answer

Please tab your code correctly.


There is no reason at all here to use a coroutine.

In addition, your checks for making sure they only get one copy are set up too complicated and incorrectly.

In addition, FindFirstChild takes a string as its parameter, not an object. We ask for an object's Name when searching for it with FindFirstChild

The resulting script is simpler:

while wait() do
	for _,Player in pairs( game.Players:GetChildren() ) do
		-------------------------------------------------------
		local Part = script.Parent
		local Character = Player.Character
		local Distance = (Character.Torso.Position - Part.Position).magnitude
		local HasGui = false
		------------------------------------------------------- 
		print(Distance)
		if Distance < 4 then
			for _,Gui in pairs (Part.GuiFolder:GetChildren())do
				Copy = Gui:Clone()
				FoundCopy = Player.PlayerGui:FindFirstChild(Copy.Name)
				if not FoundCopy then
					Copy.Parent = Player.PlayerGui
				end
			end
		end
	end
end

I renamed some of your plural variables to singular to better reflect the fact that they are not collections of multiple things but just a thing in a collection.

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