Can't clone items into my backpack with remote event

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    im trying to clone a shotgun from serverstorage into my backpack from remote event

  2. What is the issue? Include screenshots / videos if possible!
    no errors appear in the output when i fire the script besides a error that says "xXparraketXx is not a valid member of Players “Players” but the shotgun doesn’t appear

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i’ve looked over my code for errors and changed the names of variables

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local button = script.Parent
local player = game.Players.LocalPlayer
local Tool = game.ServerStorage["Shotgun"]
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Spawn")

button.MouseButton1Click:connect(function()
	if player.UserId == 1222360277 then
		remoteEvent:FireServer(Tool)
	end
end)



my localscript that fires the event

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Spawn")

local function giveitem(Item)
	if game.Players.xXparraketXx.UserId == 1222360277 then
		local copy = Item:Clone()
		copy.Parent = game.Players.xXparraketXx.Backpack
	end
end


remoteEvent.OnServerEvent:Connect(giveitem())

the script in serverscript service that attempts to clone the shotgun into my inventory

(the error i was talking about in the beginning)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

ServerStorage cannot be accessed by the client.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("Spawn")

local function giveitem(player,Item)
	if player.UserId == 1222360277 then
		local copy = Item:Clone()
		copy.Parent = player.Backpack
	end
end


remoteEvent.OnServerEvent:Connect(giveitem)

This true ServerScript
you must put shotgun in ReplicatedStorage not in ServerStorage

im using a script in serverscript service to spawn it in my inventory not a localscript

K I’m writing a source rewrite for you, one moment.

if i put it in replicated storage then the serverscripts inside it won’t work right?

--[CLIENT]--
local Spawn = game:GetService("ReplicatedStorage"):WaitForChild("Spawn") :: RemoteEvent
local UserId = game:GetService("Players").LocalPlayer.UserId :: number
local Button = script:FindFirstAncestorWhichIsA("GuiButton") :: GuiButton

Button.MouseButton1Up:Connect(function(): ()
	if UserId == 1222360277 then
		return Spawn:FireServer("Item Name" :: string)
	end
end)

--[SERVER]--
local Spawn = game:GetService("ReplicatedStorage"):WaitForChild("Spawn") :: RemoteEvent
local ServerStorage = game:GetService("ServerStorage") :: ServerStorage

Spawn.OnServerEvent:Connect(function(player: Player, Item: string): ()
	if player.UserId == 1222360277 then
		local Item = ServerStorage:FindFirstChild(Item :: string) :: Instance?
		local Backpack = player:FindFirstChildWhichIsA("Backpack")
		if typeof(Backpack) == 'Instance' and typeof(Item) == 'Instance' then
			local Clone = Item:Clone()
			Clone.Parent = Backpack
		end
	end
end)

Replace Item Name with your desired Item, notice the usage of player in a RemoteEvent.

2 Likes

the reason im putting it in serverstorage is because when i clone it directly from a localscript the scripts inside won’t work, im fairly new to scripting so i might be wrong or confusing on some stuff

local button = script.Parent
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = ReplicatedStorage:WaitForChild("Shotgun")
local remoteEvent = ReplicatedStorage:WaitForChild("Spawn")

button.MouseButton1Click:connect(function()
	if player.UserId == 1222360277 then
		remoteEvent:FireServer(Tool)
	end
end)

Check the source I’ve provided, it instead utilizes strings to get the tool. You provide the string to the server, and the server will validate your UserId before giving you the tool.

Wow thank you, it works perfectly

1 Like