The first argument is the player that sent it, so you should first have the player sending it then the player you want to have the gui visible to. Also, with Filtering Enabled, I don't believe you can see a PlayerGui in server side. You may want to use RemoteEvents in this case, and I will show you the code you should use.
First, create a remote event and name it. In this case, I will name it giveItem.
LocalScript inside button:
local Player = game.Players.LocalPlayer
local button = script.Parent
button.MouseButton1Down:connect(function()
if game.Players:FindFirstChild(button.Text) then
game.ReplicatedStorage.giveItem:FireServer(game.Players:FindFirstChild(button.Text))
end
end)
This will find the player and send it to the server.
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.giveItem.OnServerEvent:connect(function(player, sentPlayer)
ReplicatedStorage.giveItem:FireClient(sentPlayer)
end)
This will receive the request and tell the player being requested that the GUI needs cloned and moved.
LocalScript in InventoryGUI:
game.ReplicatedStorage.giveItem.OnClientEvent:connect(function()
local temp = script.Parent.Template:Clone()
temp.Parent = script.Parent.Folder
end)
This will receive the server request to clone the Template and put it in the Folder, you may add arguments too for editing the template.
If you need further help, please comment below so I can assist you!
EDIT:
If you wanted to use one script, do the following:
In the localscript with OnClientEvent, replace it with this code, and delete the code in the buttons.
local buttons = script.Parent.Buttons
game.ReplicatedStorage.giveItem.OnClientEvent:connect(function()
local temp = script.Parent.Template:Clone()
temp.Parent = script.Parent.Folder
end)
for i,button in pairs (buttons:GetChildren()) do
if button:IsA('TextButton') or button:IsA('ImageButton') then
button.MouseButton1Down:connect(function()
if game.Players:FindFirstChild(button.Text) then
game.ReplicatedStorage.giveItem:FireServer(game.Players:FindFirstChild(button.Text))
end
end)
end
end
1 comment
Remote events and functions will add the player as the first argument for you as Roblox knows who sent the request. You do not need to add the player when calling the remote event or function.