This is a script located in serverscriptservice. All it does is once the gui called "Employer" has been clicked to send items it fires a remote event that will then clone the items from the person using the "Employer" Gui and give them to the person whose name has been written in plrname (plrname is a textbox). Please help! Thanks in advance!
game.Players.PlayerAdded:Connect(function(player) game.ReplicatedStorage.fyg.OnServerEvent:Connect(function() for i,v in pairs(game.Players:GetChildren()) do local fu = v:FindFirstChild("PlayerGui") local fa = fu:FindFirstChild("Employer") local fe = fa:FindFirstChild("Frame") local fo = fe:FindFirstChild("plrname") local plr = game.Players:FindFirstChild(fo.Text) local pack = plr.Backpack for i,v in pairs(player.Backpack:GetChildren()) do v:Clone().Parent = pack end end end) end)
EDIT: the script to fire the remote event contains:
script.Parent.MouseButton1Click:Connect(function() local event1 = game.ReplicatedStorage.fyg event1:FireServer() if game.ReplicatedStorage.orders.order.Value == 1 then game.ReplicatedStorage.orders.order.Value = game.ReplicatedStorage.orders.order.Value -1 end end)
You don't need the onserverevent event inside the playeradded event.
game.ReplicatedStorage.fyg.OnServerEvent:Connect(function(plr) local fu = plr:FindFirstChild("PlayerGui") local fa = fu:FindFirstChild("Employer") local fe = fa:FindFirstChild("Frame") local pack = plr.Backpack for i,v in pairs(player.Backpack:GetChildren()) do v:Clone().Parent = pack end end)
The event returns the player so you don't need playeradded event to get the player which fired the remoteevent.