cybers2001 Posted October 30, 2025 Share Posted October 30, 2025 (edited) Just got this script working, and thought I would share. Would've saved me a lot of time if I just knew how to do this from the start! scripts/components/foobarthing.lua global("TheFooBarThing") TheFooBarThing = nil local FooBarThing = Class(function(self, inst) TheFooBarThing = self self.inst = inst self.foo = "bar" self.net_foo = net_string(self.inst.GUID, "foobarthing_foo", "foobarthing_foodirty") -- Initializing for Server if TheWorld.ismastersim then self.foo = "masterbar" self.net_foo:set("masterbar") -- Initializing for Client else self.inst:ListenForEvent("foobarthing_foodirty", function(inst) self.foo = self.net_foo:value() end) end end) return FooBarThing modmain.lua AddPrefabPostInit("forest_network", function(inst) inst:AddComponent("foobarthing") end) AddPrefabPostInit("cave_network", function(inst) inst:AddComponent("foobarthing") end) AddPlayerPostInit(function(inst) inst:ListenForEvent("setowner", function(inst) if inst == GLOBAL.ThePlayer then inst:DoTaskInTime(1, function(inst) print("!!!! foo = " .. GLOBAL.TheFooBarThing.foo) end) end end) end) If you check your client_log.txt, you should find a line that says: !!!! foo = masterbar Edited October 30, 2025 by cybers2001 Link to comment https://forums.kleientertainment.com/forums/topic/168579-tutorial-easy-custom-global-entity-that-syncs-from-server-to-client/ Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now