I am in the process of making a cabin assignment system for a cruise ship. I am attempting to have keys that have a unique identity to the player cloned into ReplicatedStorage. Unfortunately, it's not working. Whenever I attempt to clone the key from the backpack to RS, the console prints a "CabinKey is not a valid member of Backpack" error. Not sure why, because CabinKey is in Backpack. Please note, all the code functions properly except for the last line. The tool clones just fine into my backpack.
game.Players.PlayerAdded:connect(function(Player)
Player.Chatted:connect(function(msg)
if Player:GetRankInGroup(2874319) >= 240 or Player.Name == "LoonyLeftist" then
if string.sub(msg,1,9) == "giveCabin" then
local plr = "Nil"
local players = {}
local length = string.len(string.sub(msg,15,string.len(msg)))
for i,v in pairs(game.Players:GetChildren()) do
table.insert(players,v.Name)
end
for i,v in pairs(players) do
if string.sub(msg,15,string.len(msg)) == string.sub(players[i],0,length) then
plr = players[i]
end
end
for i,v in pairs(game.Players:GetChildren()) do
if string.lower(v.Name) == string.lower(plr) then
player = v
end
end
if plr ~= "Nil" then
game.ServerStorage.CabinKey:Clone().Parent = player.Backpack
player.Backpack.CabinKey.Handle.Value.Value = string.sub(msg,11,13)
player.Backpack.CabinKey.Handle.Player.Value = plr
player.Backpack.CabinKey.Name = string.sub(msg,11,13)
player.Backpack.CabinKey:Clone().Parent = game.ReplicatedStorage
else
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://595978693"
sound.Parent = Player.PlayerGui
sound:Play()
end
end
end
end)
end)
--giveCabin B02 Dj
--1234567890123456
Any help would be greatly appreciated!

9 comments
Don't use Lighting as storage, use ReplicatedStorage/ServerStorage.
Also, your if statement is effectively useless unless you're worried about a player object becoming a string or a player named Nil joining your game. I doubt he did anything that merits not allowing him into this if statement. :((
There's no context. The reason I have that is because this entire script is based on chat commands. So, if you attempt to give a key and a player wasn't selected, then the player will be nil and a sound will play indicating that no key was given.
The player will be nil, not "Nil".
I posted the rest of the code. I use the variable "Nil" to ensure that a player is properly selected when giving a key out. I'm only concerned because when I attempt to clone the key from the player's backpack into RS, it says that the key is not a valid member of backpack.
game:GetService("ReplicatedStorage") ?
Is the object you're trying to copy has its Archivable property set to true? If not, it will not copy the object and will show an error "attempt to index a nil value" because the object has not been created.
Anyways the cloned items are nil when they are parented in replicatedstorage
If The Tool Gets Equipped Then It Gets Moved To The Character, Might Be It