I’m trying to switch from collection service to check character states like “Stunned”, “Attacking”, “Ragdoll”, to dictionaries, i rarely ever used them but i know they are very useful. This is what i got for now:
The code is kinda messy, but I’ll try my best to help you out.
So the error you’re getting simple states that charState[id] is set to nil. Doing nil[“Stunned”] is wrong, and therefore throws you that error. Conclusion: charState[id] has not been initialised properly.
How to fix the issue? Maybe SetCharState() has not been called before using CheckCharState(), thus the dictionary returning nil.
Overall, whenever your table/dictionary seems to have weird values, I would always print it and then see what’s going on.
In terms of keeping your code relatively clean and easy to debug, I would recommend naming things properly. When I first read the variable “things” in function.SetCharState(things), I didn’t know what I was expecting.
On another personal level, I dislike the idea of abbreviating your variables. Instead of “plr”, do “player”. Instead of “dura”, do “duration”. Looks much better (again, this is personal. I didn’t have to think long for what “dura” meant)
i fixed the issue and it worked for actual players, but when i tried attacking the dummy (Which obviously doesnt have a player and a userid) it threw me an error, i printed the CharacterState and it was correctly assigned, now im trying to figure out how to make it if char doesnt have a player, then getattribute(“UserId”) which is complicated idk if you can help me out