Prajdo Posted May 25, 2021 Share Posted May 25, 2021 Hi everyone. I have a little problem with some coding again. This time I'm trying to add custom prefab with function to talk something randomly. After some time I came up with something like this: local talk_time = 10 * (0.8 + 0.4 * math.random()) inst:DoPeriodicTask(talk_time, function(inst) local x, y, z = inst.Transform:GetWorldPosition() local ents = GLOBAL.TheSim:FindEntities(x, y, z, 16, { "player" }) ent = ents[1] if ent and ent.userid ~= nil then if math.random() < 0.5 then inst.components.talker:Say("X") inst.SoundEmitter:PlaySound("Z", "talk") else inst.components.talker:Say("Y") inst.SoundEmitter:PlaySound("Z", "talk") end end end) My prefab is talking properly. It can say both "X" and "Y" randomly but my problem is with soundemitter which is triggering only once. I don't know how should I write it the way so each time my prefab is talking a sound is repeated. Maybe someone have any ideas? Link to comment https://forums.kleientertainment.com/forums/topic/130277-talker-problem/ 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