How would I get a data variable from a go object into a gui object

I’m trying to create two health bar for two player characters which use the same collection, the hp value is stored inside the collection, as well as each individual ID

The issue is that for me to scale the hp bar, I am going to need the values of the hp and id in the gui object, however I have not found a way to do this

both these values are stored as self. values due the characters using the same code

I’ve tried using global functions and But I can’t access self with the former and can’t return a value with the later.

Any ideas

You could store the values in a module or use messages.

It’s a one-way data flow (game object → GUI script) so you don’t need a return value. Something like:

-- In player script
local function take_damage(self, amount) = - amount"hud", "set_health", { id =, health = })
-- In HUD script
function on_message(self, message_id, message, sender)
    if message_id == hash("set_health") then
        if == "player1" then
        elseif == "player2" then
1 Like