certif Posted November 10, 2023 Share Posted November 10, 2023 function GLOBAL.radio1(speech1) for k,v in pairs(Ents) do if v.prefab == "grass" then v.components.talker:Say(speech1) end end end For context, grass already has talker component. This is in my modmain right now, and I'm trying to make it so all the grass will say whatever is typed into "speech1". like radio1("hi") I keep getting: bad argument #1 to 'pairs' (table expected, got nil) in the console whenever I try that. But typing for k,v in pairs(Ents) do if v.prefab == "grass" then v.components.talker:Say("hi") end end into the in-game console works just fine. I'm probably missing something obvious or messing something up. Thanks. Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 10, 2023 Share Posted November 10, 2023 Try GLOBAL.Ents, since you're in the modmain environment. 1 Link to comment Share on other sites More sharing options...
certif Posted November 10, 2023 Author Share Posted November 10, 2023 ah that worked perfectly. Thanks again! (again) 1 Link to comment Share on other sites More sharing options...
certif Posted November 11, 2023 Author Share Posted November 11, 2023 Looks like for some reason, the only person who can see the "hi" text coming from the grass is the host of the server. Not sure what I've done wrong here. The text just doesn't show on the other players screens. Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 11, 2023 Share Posted November 11, 2023 How are you adding the component "talker" to Grass? This is one of the few components that needs to be on the client too. How are you running the command? If you're hosting with Caves, you'll see it says either Local or Remote on the left side of the box where you type text. Make sure it's sent as Remote, meaning as the server. You toggle between them with CTRL. 1 Link to comment Share on other sites More sharing options...
certif Posted November 12, 2023 Author Share Posted November 12, 2023 Ah thanks. inst:AddComponent("talker") inst.components.talker.fontsize = 25 inst.components.talker.font = TALKINGFONT inst.components.talker.colour = Vector3(0.2, 0.4, 0.8) inst.components.talker.offset = Vector3(0, 0, 0) What should I do for it to appear for the clients? Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 12, 2023 Share Posted November 12, 2023 7 hours ago, certif said: What should I do for it to appear for the clients? If you want to add the component to clients too, just put the code before the usual "if not TheWorld.ismastersim return inst end", rather than after. That's what determines if something is both on client and server (before) or only server (after). 1 Link to comment Share on other sites More sharing options...
certif Posted November 13, 2023 Author Share Posted November 13, 2023 I think that also might explain why my code that turns wardrobes into containers is crashing clients. Thanks! Link to comment Share on other sites More sharing options...
certif Posted November 13, 2023 Author Share Posted November 13, 2023 alright turns out its still not working. Tried using radio1("hi") and the clients cannot see the "hi" even though I can see it as the host. im probably missing something obvious. Link to comment Share on other sites More sharing options...
ClumsyPenny Posted November 13, 2023 Share Posted November 13, 2023 I just tested it with another player in the server, it works fine for me, they have the mod and they can see it. Here's my code in modmain: AddPrefabPostInit("grass", function(inst) inst:AddComponent("talker") if not GLOBAL.TheWorld.ismastersim then return inst end end) function GLOBAL.radio1(speech1) for k,v in pairs(GLOBAL.Ents) do if v.prefab == "grass" then v.components.talker:Say(speech1) end end end I'll reiterate on this point though, it's very important or only you will see the text: On 11/11/2023 at 5:56 PM, ClumsyPenny said: How are you running the command? If you're hosting with Caves, you'll see it says either Local or Remote on the left side of the box where you type text. Make sure it's sent as Remote, meaning as the server. You toggle between them with CTRL. 1 Link to comment Share on other sites More sharing options...
certif Posted November 13, 2023 Author Share Posted November 13, 2023 Ah I fixed it. I had changed the prefab from grass to radio1 (after i got your advice about global.theworld.ismastersim) and the radio1 was in a container. The players couldn't see the dialog from the container, but they could see it again when I took it out of the chest and dropped it on the ground. The container was the issue. Sorry about that! And thanks for helping so much! 1 Link to comment 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