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

How do I fix the swapping function for my Inventory system?

Asked by 2 years ago

I've been working on an inventory system for a survival game I've been working on, and I've been having trouble with it. I've been lately working specifically on the swapping function, where you can select an item, press a button, and then if you press 1 for example, the selected item will go in slot 1 of the hotbar. However, when I programmed the code for the swapping to actually happen, it didn't work. I believe it was due to the updateDisplay function and how it works, since the item's data was still in the hotbar slot.

Code is below (go to lines 116 and 188 ):

001local StarterGui = game:GetService("StarterGui")
002local Players = game:GetService("Players")
003local UIS = game:GetService("UserInputService")
004 
005StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
006 
007local player = Players.LocalPlayer
008local backpack = player.Backpack
009local char = player.Character
010 
011local GUI = script.Parent.Parent.Inventory
012local hotbar = GUI.Hotbar
013local inventory = GUI.Inventory
014local items = inventory.Items
015 
View all 263 lines...

1 answer

Log in to vote
0
Answered by
blowup999 659 Moderation Voter
2 years ago

You're using equipButton.MouseButton1Click:Connect(swapItemSlots)

That will only call the function if the player clicks. If you use game:GetService("UserInputService").InputBegan:Connect(swapItemSlots) it should work because it will be called when any kind of input is passed by the player.

Ad

Answer this question