Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make a gun go in your backpack on click?

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.

2 answers

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)

2 comments

0

ReplicatedStorage is intended as a replacement for the Lighting service.

0

Oh. Sorry.

This discussion is preserved as it was. New answers, comments, and votes are closed.