Adjusting Speed (Bug issues)

I’ve always had this issue where I have a shift to sprint sprint key, and it changes up the speed of my character so i’m faster and running. The issue about this, is how messy it can get when I add stuff like ‘Player Stuns’. If you stun a player they can simply just deactivate their sprint button, and boom they’re unstunned.

While there’s a decent amount of messy ways to fix this issue (e.g adding stun values and checking if they’re stunned or not which would still be buggy if a player was lagging), I’d appreciate it if there was a more efficient way of dealing with this bug.

1 Like

I’d suggest using boolean logic. It seems simple but it can be really powerful and useful in instances like this.

For example:

function sprint()
    if not stunned then
        -- change their speed
        -- handle what happens when they're stunned and try to sprint
1 Like

Good idea, I could try using _G method or adding speed adjustments to 1 localscript.

I’d suggest not using _G for something like this. I’d also suggest only using one localscript per client. This is because you can get conflicting behavior in scripts or be stuck waiting for events in other scripts just to communicate between them. If you want to organize your code, use modulescripts.

As for using _G, I’ve been told that it is slow to write to, so you’d end up waiting for values to be written if you wanted to use it. Aside from being slow, there are more ideal solutions to consider, such as just using one script.

1 Like