So this is my code so far
game.Players.PlayerAdded:connect(function(player) player:WaitForChild("PlayerGui") game.ServerStorage.FE.ChangeParent:FireServer(game.ServerStorage.GUIs.Intro:Clone(),player.PlayerGui) end)
That script basically gives the GUI to the player and it's FE so yeah, that's why
local ChangeParent = game.ServerStorage.FE.ChangeParent ChangeParent.OnServerEvent:connect(function(object,parent) object.Parent = parent end)
This is the remote event and the thing for it and I get this error when I do
19:47:26.843 - Something unexpectedly tried to set the parent of trycode to Intro while trying to set the parent of trycode. Current parent is Players.
Can you help me? :)
PLEASE READ THE WHOLE ANSWER PLEASE. THIS INCLUDES A FEW CHANGES IN YOUR HIERARCHY!
A minor mistake that you did is not include the player parameter
. This is why the error
states your username. The script
thinks that your object
is the player
. Here is the revised part.
Another mistake that you have done is that you put your ChangeParent
Remote Event
in ServerStorage
. This is a wrong thing to do because only the server
can access the ServerStorage
service. Put it in ReplicatedStorage
so both the client
and server
can access it
Make sure the script below is a Local Script
local ChangeParent = game.ReplicatedStorage.FE.ChangeParent ChangeParent.OnServerEvent:connect(function(player,object,parent) object.Parent = parent end)
You did this part correctly
Make sure the script below is a Server Script
game.Players.PlayerAdded:connect(function(player) player:WaitForChild("PlayerGui") game.ReplicatedStorage.FE.ChangeParent:FireServer( game.ReplicatedStorage.GUIs.Intro:Clone(), player.PlayerGui ) end)
Simple mistake here. The only problem that I can see is that you are using incorrect parameters for the OnServerEvent event. The first argument is always the player whose client is invoking the event. So your code should look something more like this:
local ChangeParent = game.ServerStorage.FE.ChangeParent ChangeParent.OnServerEvent:connect(function(player, object, parent) object.Parent = parent end)
As you can see, all I did was add the 'player' argument into the function. It should now work fine. If not or if you have any further questions let me know and I'll see what I can do. Hope this helps :)