I'm trying to make a fighting simulator (I'm not asking codes to make the game only codes to put stuff in the backpack), I don't how to put weapons in your backpack, how?
How do you put e.g a weapon into your backpack?
1 answer
When a tool is not equipped, it is in the backpack. When a tool is equipped, it is in the character.
So with that info we can do this:
game.ReplicatedStorage.ToolSystem.OnServerEvent:Connect(function(player, toolName)
local Backpack = player.Backpack
local Character = player.Character
local tool = Backpack[toolName] or Character[toolName] -- If it does not see it in the backpack then it will look in the character
if tool.Parent == Backpack then
tool.Parent = Character
elseif tool.Parent == Character then
tool.Parent = Backpack
end
end)
-- And now from the client
local ToolSystem = game.ReplicatedStorage.ToolSystem
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.KeyCode == Enum.KeyCode.1 then
ToolSystem:FireServer("tool name here")
end
end
end)
This is the way it works:
Client: So on the client whenever the player presses a key then, if the the player is not hovering over any other gui or typing in chat (gameProcessedEvent) then, if the key is equal to any key (ex.1) then, the client fires the remote event.
Server: The server picks up any requests from the client. So I stored the character and the backpack in two seperate variables. Then, I checked to see if the tool was in the backpack, then if it was I changed it to the character. Then, I checked to see if the tool was in the character, then if it was I changed to the backpack.
I hope this helps :)
2 comments
Thanks SO SO Much
No problem!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
You are not looking for codes so here you go. https://developer.roblox.com/en-us/api-reference/class/Backpack
err. are you sure