tr1ckzy Posted October 18, 2023 Share Posted October 18, 2023 Hi there! I'm brand new to lua and modding in general and I wanted to create a mod that plays a sound whenever the player yells. I wrote a piece of code that gives me an error whenever I press Q in game - "Object tried to call nil in OnCustomUIKeyPressed at KahluaUtil.fail line:82." Heres the code: Quote local OnCustomUIKeyPressed = function(qtaunt) if qtaunt == Keyboard.KEY_Q then qtaunt:playSound("yell_" .. ZombRand(1, 15)) end end Events.OnGameStart.Add(OnGameStart); Events.OnCustomUIKeyPressed.Add(OnCustomUIKeyPressed) I'm even more confused because I wrote the exact same code, but made it play a sound whenever a zombie is killed and it works perfectly fine. Here's the code that works: Quote local onZombieDead = function(taunt) local rng = ZombRand(2) if rng == 1 then taunt:playSound("taunt_" .. ZombRand(1, 19)) end end Events.OnGameStart.Add(OnGameStart); Events.OnZombieDead.Add(onZombieDead) Any help would be appreciated! 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