You can write your topic however you want, but you need to answer these questions:
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
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
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
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.
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
--[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.
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.