#Updating visual info on table change
1 messages · Page 1 of 1 (latest)
detect when the equipped towers are changed and update the icons
Make a function to update it whenever something happens
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local CoreEvent = ReplicatedStorage.RemoteEvents.CoreEvent
local InventoryGui = Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("MainGui"):WaitForChild("Inventory")
local player = Players.LocalPlayer
local function ToggleInventory(input, processed)
local uiClick = script.UIClick
uiClick:Play()
for i, v in pairs(InventoryGui.Icons:GetChildren()) do
if v:IsA("ImageButton") and v.Name ~= "IconTemplate" then
v:Destroy()
end
end
local profileData = ReplicatedStorage.RemoteFunctions.GetProfile:InvokeServer(player)
for i, tower in pairs(profileData.Inventory) do
local towerModel = ReplicatedStorage.Towers:FindFirstChild(tower)
local towerIcon = InventoryGui.Icons.IconTemplate:Clone()
towerIcon.Name = tower
towerIcon.Image = towerModel.Config.Hotbar.Image.Texture
towerIcon.Parent = InventoryGui.Icons
towerIcon.Visible = true
towerIcon.Activated:Connect(function()
print("CLICKED")
-- Clear previous tower info
InventoryGui.Info.Visible = false
InventoryGui.Info.TowerName.Text = ""
InventoryGui.Info.EquipButton.Visible = false
-- Create tower info
InventoryGui.Info.Visible = true
InventoryGui.Info.TowerName.Text = towerModel.Name
InventoryGui.Info.EquipButton.Visible = true
if table.find(profileData.Equipped_Tower, towerModel.Name) then
print("InTable")
InventoryGui.Info.EquipButton.Text = "Unequip"
elseif not table.find(profileData.Equipped_Tower, towerModel.Name) then
print("NotInTable")
InventoryGui.Info.EquipButton.Text = "Equip"
end
end)
end
if InventoryGui.Visible == false then
InventoryGui.Visible = true
else
InventoryGui.Visible = false
end
end
UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.E then
if not processed then
ToggleInventory()
end
end
end)
InventoryGui.Parent.InventoryOpen.Activated:Connect(function()
ToggleInventory()
end)
InventoryGui.Info.EquipButton.Activated:Connect(function()
CoreEvent:FireServer("Tower", InventoryGui.Info.TowerName.Text)
end)
this is loca
local
classic problem
whats that even mean?
it's a problem that affects many things in ui
inventory is often the first
so how does classic work and how do i fix it
whenever complex data changes, you have to update the ui as well if it is currently open
and how do i update the ui?
depends on what it is and how you have it set up
bunch of different ways to listen for changes
this is my current local script
ya you wrote it so you should know it better than anyone else
no i just mean the problem is just very common
okay, and what would you suggest is a way to go around it, iv already established that the ui isnt updating, i just dont know how to make it update
local profileData = ReplicatedStorage.RemoteFunctions.GetProfile:InvokeServer(player) newb trap
you probably can't get live updates from this since you only fetch the data once when it opens, and this is currently your only way to discover changes
A function?
xD
im new to profilestore, what should i do different?
doing it properly involves streaming the changes, so the server can inform the client of changes as they happen and the client reacts accordingly
rather than the client actively requesting the entire chunk of data at one particular moment when its needed
this has nothing to do with profilestore anymore
im terrible at everything to do with player data
profilestore is where your data is coming from; the inventory table
literally my weakest point
now you have to do something else to get that inventory table to the client in a way that the client can listen for changes to it
there's so many ways you could do this
one rather naive way is to turn all the data in your inventory table into instances like have a folder for each item and a string/number value for each field, or you can use attributes in some way. and this is just one way and it is particularly beginner friendly. more advanced way is to use remote events to send the whole table once then small changes like 'change inventory slot x to y item with z count' 'empty slot b' aka the "delta" (change-of) etc
iv seen people do it with instances, and i really dont want to go down that route
too bad
you're not yet skilled enough to do it the advanced way
you mean like, send the data back with an event here?
in your opinion
i suppose you could work that into what you need 🤷
the concept doesn't change, this is rather universal to a lot of things particularly for ui
I did it, made the event fire back from server after updating the table, it only sends back the changes and updates them accordingly, also added a ui update feature to reset the ui to the new data after the equip button is activated