RemoteEvent with GetChildren()?

Because it doesn’t read me what is inside the test folder

localscript

local y = script.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	
	script.Parent.Parent.ImageButton:Clone().Parent = script.Parent.Parent.Parent.test
	game.ReplicatedStorage.RemoteEvent:FireServer(y)
	
end)

script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(y)

	for o,q in pairs(y:GetChildren()) do
		if q.Name == "PlayerGui" then
			for o,w in pairs(q:GetChildren()) do
				if w.Name == "test" then
					for o,e in pairs(w:GetChildren()) do
						print(e)
					end
				end
			end
		end
	end
end)
1 Like

Does the Instance y exist on the server where you’re trying to get it?

3 Likes

On the server side, when you’re calling the remote using OnServerEvent, the first argument must be the player, so try to do
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) [if you only need the player]

It looks like you’re passing an argument on the local side, so it means you have to have 2 arguments in the server side

and on the client try this -

local y = script.Parent.Parent.Parent
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.ImageButton:Clone().Parent = script.Parent.Parent.Parent.test
	remote.RemoteEvent:FireServer()
end)
3 Likes

The first argument will always be the player and by putting “player” as the first parameter it will just make an empty parameter.

2 Likes

If you have n arguments in the FireServer(), you must have n+1 arguments in the OnServerEvent(),
apparently it doesnt look like he need that ‘y’, he can access the player’s GUI even without it

1 Like

Why it is n+1?

I can’t even figure out the issue because nothing tells you what the variables are and is just nameing it with singular letters so I am unable to help in the situation.

localscript

local y = script.Parent.Parent.Parent
local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.ImageButton:Clone().Parent = script.Parent.Parent.Parent.test
	remote.RemoteEvent:FireServer()
end)

script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, y)

	for o,q in pairs(y:GetChildren()) do
		if q.Name == "PlayerGui" then
			for o,w in pairs(q:GetChildren()) do
				if w.Name == "test" then
					for o,e in pairs(w:GetChildren()) do
						print(e)
					end
				end
			end
		end
	end
end)
2 Likes

From what it seems like you’re trying to access the PlayerGui from player by .Parent. If you want to access the player from a LocalScript you can just use game:GetService("Players").LocalPlayer. - access player locally

But since the player is already passed in the function parameter connected to the RemoteEvent.OnServerEvent by default you can define the PlayerGui on the server instead with local PlayerGui = player:WaitForChild("PlayerGui") - get the PlayerGui with player trough the function parameter

So technically the OnServerEvent will look like this (player) even though you won’t see it. - then of course you can pass other arguments in the parameter

So to get the “test” instance in your PlayerGui you can simply do

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player) -- if y is player then player is the same as y to clarify
    local PlayerGui = player:WaitForChild("PlayerGui") -- define the PlayerGui in the variable
    if PlayerGui then -- if you really want to make sure it exists
        for index, instance in pairs(PlayerGui:GetChildren()) do
            if instance.Name == "test" then
                for a, child in pairs(instance:GetChildren()) do
                    print(child)
                end
            end
        end
    end
end)

This script should get the PlayerGui and scan it for “test” then get the Children of “test” and print them out in the console.

Hope this helped you to better achieve your goal :slight_smile:

5 Likes

sorry if I tell you I tried the script but it doesn’t mida the Children

2 Likes

What is your goal with your script, what do you want to achieve?

2 Likes

I want to get things that are put into test to duplicate and put into SurfaceGui

2 Likes

If you want to do that locally you can get the “test” by doing this

local Players = game:GetService("Players")
local PlayerGui = Players.LocalPlayer:WaitForChild("PlayerGui")

PlayerGui.ChildAdded:Connect(function(Child)
    if string.match(Child.Name, "test") then
        for index, instance in pairs(Child) do
            -- not knowing where your SurfaceGui is makes it difficult to provide you with an accurate example
        end
    end
end)

This snippet checks every child that is added to the PlayerGui and if the name of child is “test” then it will get the children of “test”. Then you need to locate your SurfaceGui and if you want to duplicate them you can do.

local clone = instance:Clone()
clone.Parent = --SurfaceGui

Also make sure to set Visible of instance to true if it isn’t already set to true. :slight_smile:

3 Likes

Sorry but what is instance?
(to what is it brought back)

3 Likes

instance is a placeholder name for each individual child of “test”

3 Likes

Cannot see ImageButton

Replace instance:Clone() with child:Clone() since child is each individual child in “test” in this case the only child is ‘ImageButton’

3 Likes

1 Like

You never replaced instance:Clone() with child:Clone()

3 Likes

Sorry wrong video regards it should be right now

2 Likes

sorry the video was wrong now i put the right one

2 Likes