Hi, I know this is a very specific question, since there is probably not many devs using weapon kit, so there is not many potencial helpers, but I am struggling to understand how can I implement my own weapon models (my guns) into the game and how can I remove a weapon from player’s backpack or add it to backpack by the script. Thanks for help!!
You can add the weapon / knife in ReplicatedStorage and create a script in ReplicatedStorage. So create a variable to player and character to get player’s backpack.
local player = game.Players.LocalPlayer
local character = player.Character
local backpack = character:FindFirstChild ("Backpack")
game.ReplicatedStorage.(NAMEOFYOURGUN):Clone().Parent = backpack
And you can remove it by using a i, v loop like
for i, v in pairs(game.Players:GetChildren())
if v.Name == "Backpack" then
v:FindFirstChild("NAMEOFYOURGUN"):Destroy()
hmm your answers doesnt seem to be legit… I am mostly confused buy your path to backpack, usually a backpack is a child of a player and not he’s character, also u are looping through all of the players and expecting to find a player named “Backpack”?
No, the line for i, v in pairs (game.Players:GetChildren()) takes all objects that are parented to the players. The backpack is one of the objects. So, in the line if v.Name == "Backpack" then is saying, if the object name is “Backpack”, then do: destroy gun. I don’t know if it is now easy to understand.
no I still dont understand it, I have over a year of scripting experience and I am confused, because basically what u are saying is this:
for i, v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Name == "Backpack" then -- "v" is a player
end
end
I didn’t put :GetPlayers in the script, I put game.Players:GetChildren ()), so the script will automatically pick up all the childrens in the player.
You are getting the players instead of the backpack or the items inside the player. You should do game.Players:GetPlayers() and then use GetChildren().