I made a gui to create your own group within a game and I need to make a invite button so other people can invite another player to that group, and i tested this script but it doesn't seem to work, and the error seems to say playergui is not a valid member of player.
local plr = game.Players.LocalPlayer local stats = plr:WaitForChild("leaderstats") local group = stats:WaitForChild("Affiliation") local money = stats:WaitForChild("Money") local nameofgroup = script.Parent.Parent:WaitForChild("NameGroup") local otherplayer = script.Parent.Parent:WaitForChild("InvitePlayerName") script.Parent.MouseButton1Click:connect(function() for i,v in pairs(game.Players:GetPlayers()) do if v.Name == otherplayer.Text then local pgui = v:WaitForChild("PlayerGui") local groupframe = pgui:WaitForChild("GroupGUI"):WaitForChild("GroupFrame") local joinframe = groupframe:WaitForChild("JoinFrame") local clone = game.ReplicatedStorage["JoinGroup"]:Clone() for j,k in pairs(clone:GetChildren()) do if k.Name == "Name" then k.Text = group.Value end clone.Parent = joinframe end end end end)
Explanation
Your error is telling me that you are doing this from the server.
Playergui
only exists on the client
(because why the hell would you try to edit a user interface fro m the server)
Same with LocalPlayer
Solution
You should make a RemoteEvent
, two localscripts
and a server script
, then on one localscript
fire a remotevent
when the invite button is clicked then on the server fire another remotevent
to tell the other localscript
that it should display the invite.
Side Note
If you didn't understand the solution, you should follow tutorials and learn how to code properly before trying to make a game.