I am attempting to create an item storage and tool usage system. I have everything working, but if you equip a tool in the hotbar and move it to another slot in the inventory, or still the hotbar, it stays equipped. I am trying to remedy this by checking when one of the string values storing the tool/item type changes to nothing, and then sending the previous item type to a new script to unequip the item. I can’t simply store the value when the script starts running on game load, because the value changes over time, and that would not work. I need a way to detect the old value as the event fires, is there a way to do this?
Hi!
I couldn’t really understand what you want to do,
but have you tried storing an old value into the dictionary before signal fires your function?
Doing something like
local Value = Slot1.Value
Slot1:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.UnequipTool:FireServer(Value)
end)
To my understanding would not work because the item or lack thereof in the slot would change over time, as in, you might end up putting a different tool there, or a different item, So the old value would not be accurate.
Couldn’t you just have an external variable?
local prevValue = Slot1.Value
Slot1.Changed:Connect(function(newValue)
-- do something with the new value here.
-- this value can then update the prev value
prevValue = newValue
end)
I found out the solution. To get the most recent value before it changes into a new one, you need to make a second value that changes to whatever the original one changes to, but delayed. So you can access the old value for a sec, then it corrects.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.