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

How do you put e.g a weapon into your backpack?

Asked by 4 years ago
Edited 4 years ago

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?

0
You are not looking for codes so here you go. https://developer.roblox.com/en-us/api-reference/class/Backpack LinavolicaDev 570 — 4y
0
err. are you sure badimo3456p 114 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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 :)

0
Thanks SO SO Much badimo3456p 114 — 4y
0
No problem! IceyTazeForLife 253 — 4y
Ad

Answer this question