game.Workspace.Gun.ClickDetector.MouseClick:connect(function() local plr = game.Players.LocalPlayer local Item = game.ReplicatedStorage:FindFirstChild("Gun") local p = Item:Clone() p.Parent = plr.Backpack end)
For some reason, this script won't work. The Gun is in ReplicatedStorage.
LocalPlayer does not work in a regular Script.
game.Workspace.Gun.ClickDetector.MouseClick:connect(function(plr) --Putting "plr" in the parameters for the MouseClick event will assign that name as a variable to the player who clicked it. local Item = game.ReplicatedStorage:FindFirstChild("Gun") local p = Item:Clone() p.Parent = plr.Backpack end)
NOTE: Please format your code (shown above) so it is easier to read for people around ScriptingHelpers. This is done by pressing the Lua BBCode and pasting your code within the lines it makes when creating your post.
Put this script inside of the Gun
part.
script.Parent.ClickDetector.MouseClick:connect(function(player) local rs = game:GetService("ReplicatedStorage") rs.Gun:clone().Parent = player.Backpack end)