Now before you tell on me how easy It Is, let me explain, anyway I wanted this script to be a server script, so that whenever the button Is clicked, It gives you a weapon, and It does work however Its a local script, the problem is that since local scripts are for the client side, the weapons that are given to you suddenly lose there function (And If you view the server side, you will be holding nothing)
script:
local button = script.Parent local ScrollingFrame = script.Parent.Parent.Parent local Rep = game.ReplicatedStorage local Knife = Rep.Weapons["Average knife"] local Gun = Rep.Weapons.Pistol button.MouseButton1Click:Connect(function() ScrollingFrame.Visible = false local P = game.Players.LocalPlayer local CopiedGun = Gun:Clone() local CopiedKnife = Knife:Clone() CopiedKnife.Parent = P.Backpack CopiedGun.Parent = P.Backpack end)
[MARK THIS ANSWER AS ACCEPTED IF IT WORKS]
For the client to communicate with the server, you have to use something known as RemoteEvents. In order for a client to send a message to the server, it needs to fire the RemoteEvent with the function RemoteEvent:FireServer in a LocalScript.
The server meanwhile needs to connect a function to the OnServerEvent of the RemoteEvent.
When a client calls the FireServer function, any functions on the server that are connected to OnServerEvent will fire. Note that this is not immediate - the network connection between the client and server will determine how quickly this happens.
When firing a RemoteEvent from a client to the server, data can be included in the firing. By default, the functions connected to OnServerEvent will be passed the player who fired the event as the first parameter. If any other arguments are provided in the FireServer function, they will also be included in OnServerEvent after the player argument.
For your instance create a RemoteEvent in ReplicatedStorage and a script in ServerScriptService.
Configure the local script to this:
local button = script.Parent local ScrollingFrame = script.Parent.Parent.Parent local Rep = game.ReplicatedStorage local Knife = Rep.Weapons["Average knife"] local Gun = Rep.Weapons.Pistol button.MouseButton1Click:Connect(function() ScrollingFrame.Visible = false Rep.RemoteEvent:FireServer(game.Players.LocalPlayer) end)
The script in ServerScriptService should be:
local Rep = game:GetService("ReplicatedStorage") local event = Rep.RemoteEvent local Knife = Rep.Weapons["Average knife"] local Gun = Rep.Weapons.Pistol local function giveTools(player) local CopiedGun = Gun:Clone() local CopiedKnife = Knife:Clone() CopiedKnife.Parent = player.Backpack CopiedGun.Parent = player.Backpack end event.OnServerEvent:Connect(giveTools)
Your explorer should look something like this: https://prnt.sc/DwPgTGm8Gopd