Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is this tool not being cloned into ReplicatedStorage?

Asked by 5 years ago
Edited 5 years ago

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!

2
Don't use Lighting as storage, use ReplicatedStorage/ServerStorage. User#19524 175 — 5y
0
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. :(( SummerEquinox 643 — 5y
0
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. Djmaster444 5 — 5y
1
The player will be nil, not "Nil". SummerEquinox 643 — 5y
View all comments (5 more)
0
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. Djmaster444 5 — 5y
0
game:GetService("ReplicatedStorage") ? DeceptiveCaster 3761 — 5y
0
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. MatthewCenance 35 — 5y
0
Anyways the cloned items are nil when they are parented in replicatedstorage Animescapetower 10 — 5y
0
If The Tool Gets Equipped Then It Gets Moved To The Character, Might Be It User#25606 0 — 5y

Answer this question