We can have troubles while coding.
I just saw my old self here. Maybe it will take my 20-25 minutes to reply your topic, but it is okay. I’ll be typing those carefully to make you understand all the drama here!
SPOILER
I’ll use advanced english (when I’ll have to be serious of course XD) , you can translate if you don’t know english enough.
Runtime Errors
Issue: Potential Nil Value Access
-
Context:
local char = plr.Character or plr.CharacterAdded:Wait()
-
Description: If
plr.Character
is nil
, the code attempts to access the Wait()
method on plr.CharacterAdded
, which could lead to a runtime error if plr.CharacterAdded
is also nil
.
-
Suggested Fix: Add a check to ensure
plr.Character
is not nil
before attempting to access plr.CharacterAdded
.
I hope you understood what I mean. Did you…?
Code Optimization Tips
Well, my tips aren’t useful at all but maybe it can be useful for this time.
Issue: Redundant Variable Assignment
-
Context:
local db = false
-
Description: The variable
db
is initialized as false
but is only used as a flag to prevent multiple executions of the death
function. It could be optimized by directly checking if death
has been called.
-
Suggested Fix: Remove the
db
variable and directly check if death
has been executed.
Performance Bottlenecks
What a weird name,right? bOttleNecKs! Joking, let’s go on.
Issue: Redundant Delay in Event Handling
-
Context:
task.wait(0.1)
-
Description: Unnecessary delay after the player’s death event.
-
Suggested Fix: Remove the
task.wait(0.1)
to streamline event handling and improve responsiveness.
Variable Naming
Issue: Inconsistent Variable Naming
-
Context:
plr
, char
, hum
, db
, klr
-
Description: Variable names follow different naming conventions.
-
Suggested Fix: Maintain a consistent naming style across all variables, like camelCase or snake_case. Ssssss​:snake:

!!!
Potential Refactoring Spots
My fingers started to get heavy, and you got tired of reading.
Issue: Conditional Check for Player Death
-
Description: The conditional check for player death and subsequent actions can be refactored for clarity.
-
Suggested Fix: Refactor the logic to handle player death more explicitly and improve readability.
API Misuse
Issue: Incorrect Usage of GetAttribute
-
Context:
hum:GetAttribute("Killer")
-
Description:
GetAttribute
is not a standard method for Humanoid objects.
-
Suggested Fix: Use appropriate methods or properties to retrieve the desired information from the Humanoid object.
Code Smells
I know that “Code Smells” sounds quite awkward.
Issue: Global State Usage
-
Description: The variable
db
is used as a global flag to control execution flow.
-
Suggested Fix: Consider refactoring to reduce reliance on global state, which can lead to unexpected behavior and make code harder to maintain.
Compatibility Issues
That’s the last advice that I can give you.
Issue: Potential Compatibility with Future Roblox Updates
-
Description: The code may rely on specific Roblox API behaviors that could change in future updates.
-
Suggested Fix: Regularly review and update the code to ensure compatibility with the latest Roblox API changes.
I hope you’re not mad at me for not giving the fixed version of the code. But believe me, copy and paste won’t work. You’ll just forget it easily. If you still cannot fix, let me know.