LocalScript:
Calls Remote Function by pressing the Button
local Player = game.Players.LocalPlayer local button = script.Parent button.MouseButton1Down:connect(function(player) game.ReplicatedStorage.RemoteFunction:InvokeServer(player) end end)
Server Script:
Gives template image to a Player
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") function ReplicatedStorage.RemoteFunction.OnServerInvoke(player) -- Works until this moment --------------------------------------------------- local Inv = player.PlayerGui:WaitForChild("InventoryGui") local NewSlot = player.PlayerGui:WaitForChild("InventoryGui").Template:Clone() NewSlot.Parent = player.PlayerGui:WaitForChild("InventoryGui").Folder return NewSlot end
This is still working in Studio, but not on the server.
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) -- Tell the client to clone the Template. 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 --Change to where buttons are stored. 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