so i tried this code to give me a weapon on press of the button and it didnt work
local player = game.Players.LocalPlayer -- Refer to the Player local tool = game.ReplicatedStorage.Sword -- Refer to the Tool script.Parent.MouseButton1Down:connect(function() -- When it's clicked if player:FindFirstChild("Backpack") then -- Not sure why I added this tool:Clone().Parent = player.Backpack -- Clone the tool to their inventory end -- End the if function end) -- End the MouseButton1Down function
You are cloning the tool with a LocalScript, but you can only clone with a server script, I believe. You'll have to use a RemoteEvent instead.
https://developer.roblox.com/en-us/api-reference/class/RemoteEvent
Example: (make sure you have a remoteevent inside of replicatedstorage)
button script:
local player = game.Players.LocalPlayer script.Parent.MouseButton1Down:connect( function() game.ReplicatedStorage.RemoteEvent:FireServer(player) end )
backpack script inside of serverscriptservice:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect( function(player) local tool = game.ReplicatedStorage.Sword tool:Clone().Parent = player.Backpack end )