Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

1 answer

✓ Accepted 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

0

Thanks SO SO Much

0

No problem!

This discussion is preserved as it was. New answers, comments, and votes are closed.