Nhyarlathoteps Posted September 14, 2020 Share Posted September 14, 2020 (edited) I am in the process of implementing my own component and its replica and I am encountering one last problem: The oxygen replica doen't exist on the client side modmain.lua: AddPlayerPostInit(function(inst) AddReplicableComponent("oxygen") if GLOBAL.TheWorld.ismastersim then --Server inst:AddComponent("oxygen") else --Client print(inst.replica.oxygen) -- nil here and other places end end) oxygen.lua: local function onmax(self, max) self.inst.replica.oxygen:SetMax(max) end local function oncurrent(self, current) self.inst.replica.oxygen:SetCurrent(current) end local Oxygen = Class(function(self, inst) self.inst = inst self.max = 30 self.current = self.max end, nil, { max = onmax, current = oncurrent }) return Oxygen I know for sure that the replica exists on the server side because it is called by the onmax and oncurrent functions. oxygen_replica.lua: local function OnOxygendirty(inst) print(inst.replica.oxygen) end local Oxygen = Class(function(self, inst) self.inst = inst self.maxoxygen = net_ushortint(inst.GUID, "oxygen.max", "oxygendirty") self.currentoxygen = net_ushortint(inst.GUID, "oxygen.current", "oxygendirty") if not TheWorld.ismastersim then inst:ListenForEvent("oxygendirty", OnOxygendirty) end end) function Oxygen:SetCurrent(current) if TheWorld.ismastersim then self.currentoxygen:set(current) end end function Oxygen:SetMax(max) if TheWorld.ismastersim then self.maxoxygen:set(max) end end return Oxygen The replica is built like named_replica.lua Is there a mistake somewhere? References: Edited September 15, 2020 by Nhyarlathoteps Fix spoiler Link to comment https://forums.kleientertainment.com/forums/topic/121726-the-replica-of-the-component-doesnt-appear-on-the-clients-side/ Share on other sites More sharing options...
penguin0616 Posted September 15, 2020 Share Posted September 15, 2020 @NhyarlathotepsI think you have to AddReplicableComponent("oxygen") at the beginning of the script. Also, it does take time for the replica to show up on the client. It's not instanteous, but should be there very quickly. 2 Link to comment https://forums.kleientertainment.com/forums/topic/121726-the-replica-of-the-component-doesnt-appear-on-the-clients-side/#findComment-1371388 Share on other sites More sharing options...
Nhyarlathoteps Posted September 15, 2020 Author Share Posted September 15, 2020 You were right, I just had to wait a little bit, Thank you for your answer!! Link to comment https://forums.kleientertainment.com/forums/topic/121726-the-replica-of-the-component-doesnt-appear-on-the-clients-side/#findComment-1371548 Share on other sites More sharing options...
penguin0616 Posted September 15, 2020 Share Posted September 15, 2020 No problem. 1 Link to comment https://forums.kleientertainment.com/forums/topic/121726-the-replica-of-the-component-doesnt-appear-on-the-clients-side/#findComment-1371569 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