Random Guy000 Posted August 14, 2023 Share Posted August 14, 2023 So im trying to make a mod, and push an event so that when thing A happens to, say, Ben, Steve would react and do thing B. So I do something like this inst:ListenForEvent("PlayerGotNewItem", function(inst,data) if BingoMode --[[a mod setting]] == 2 then do things if data.namecalled --[[data from push event, gives the name of the player who triggered it]] ~= ThePlayer.name then do stuff end end end) But even the first check only works for me, other players don't pass it, that's what I want to fix How can I fix this and what am I doing wrong? Link to comment Share on other sites More sharing options...
Random Guy000 Posted August 14, 2023 Author Share Posted August 14, 2023 I need to do stuff to all players, besides the one who triggered the PushEvent, in simple words Link to comment Share on other sites More sharing options...
_zwb Posted August 14, 2023 Share Posted August 14, 2023 You can use the table AllPlayers to do stuff for all players Link to comment Share on other sites More sharing options...
Random Guy000 Posted August 15, 2023 Author Share Posted August 15, 2023 20 hours ago, _zwb said: You can use the table AllPlayers to do stuff for all players Can you please explain how to use it? Link to comment Share on other sites More sharing options...
_zwb Posted August 15, 2023 Share Posted August 15, 2023 1 hour ago, Random Guy000 said: Can you please explain how to use it? for _, player in pairs(AllPlayers) do print(player.prefab) end Every value in this table is a player entity. Link to comment Share on other sites More sharing options...
Random Guy000 Posted August 29, 2023 Author Share Posted August 29, 2023 On 8/15/2023 at 11:20 PM, _zwb said: for _, player in pairs(AllPlayers) do print(player.prefab) end Every value in this table is a player entity. Can you help me with this error? -- PushEvent code TheWorld:PushEvent("PlayerGotNewItem", {guy = ThePlayer, itemcalled = item, slotcalled = k}) -- Listner code TheWorld:ListenForEvent("PlayerGotNewItem", function(inst, data) if BingoMode == 2 then for _, player in pairs(AllPlayers) do if player ~= data.guy then for k,v in pairs(player.components.itemTableHandler.globList) do -- This line causes the crash if v == data.itemcalled then if player.components.itemTableHandler.globTagger[k] ~= -1 then player.components.itemTableHandler.globTagger[k] = -1 player.components.itemTableHandler:evaluateList() player.components.talker:Say("Slot #" .. k .. ", " .. v ..", is now locked") end end end end end end end) Link to comment Share on other sites More sharing options...
_zwb Posted August 29, 2023 Share Posted August 29, 2023 It seems that one of the players don't have the component? How did that happen? Did you forget to add the component to the player? Link to comment Share on other sites More sharing options...
Random Guy000 Posted August 29, 2023 Author Share Posted August 29, 2023 2 hours ago, _zwb said: It seems that one of the players don't have the component? How did that happen? Did you forget to add the component to the player? Can't really be it? Most of the code isn't mine, but even these chunks that I use here are repurpoused from the original code, which works just fine I've only switched "ThePlayer" to "player" Maybe it has to do with the fact that the original mod was client based? Link to comment Share on other sites More sharing options...
_zwb Posted August 29, 2023 Share Posted August 29, 2023 32 minutes ago, Random Guy000 said: Maybe it has to do with the fact that the original mod was client based? Aha, I see why it crashed, you cannot access components on the client side unless a replica component is made for clients, so it crashed trying to access a component Link to comment Share on other sites More sharing options...
Random Guy000 Posted August 29, 2023 Author Share Posted August 29, 2023 7 minutes ago, _zwb said: Aha, I see why it crashed, you cannot access components on the client side unless a replica component is made for clients, so it crashed trying to access a component Ok, so I figured something pretty similar to that The code that I sent was a part of a class, which was local, so naturally I just cut the local out It still crashes though, same error and all. Any suggestions on fixing that? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.