✓ Accepted answer
[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
2 comments
you cant ask for player input from a server script
About your request @imnotaguest1121 You can use getdescendants/getchildren on the "Weapons" folder and if statements. If you don't know how you can make a question about it.