RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"it still crouches even if the walkspeed doesnt equal runwalkspeed value"
The last example provided is a script that allows a player's character to toggle between crouching and standing positions in Roblox, affecting the character's walk speed, jump power, and playing a crouching animation. The issue mentioned is that the character can still crouch even if their walk speed does not match the `RunWalkSpeed` value. This behavior is due to the condition in the `ToggleCrouch` function, which only checks if the character is not already crouching before allowing them to crouch again, without considering the current walk speed relative to `RunWalkSpeed`. To address this issue and ensure that crouching is only toggled under specific conditions (e.g., when the character's walk speed is not set to the `RunWalkSpeed`), you can modify the `ToggleCrouch` function to include additional checks or adjust its logic according to your game's specific requirements. Here's a revised version of the `ToggleCrouch` function that might help clarify the intended behavior: ```lua local function ToggleCrouch() -- Check if the character is not crouching and the current walk speed is not the RunWalkSpeed. if not Crouching and Humanoid.WalkSpeed ~= script.Parent.Run.RunWalkSpeed.Value then Crouching = true Humanoid.WalkSpeed = CrouchS Humanoid.JumpPower = 0 Humanoid.JumpHeight = 0 CrouchAnimm:Play() CrouchAnimm:AdjustSpeed(0) -- If the character is crouching, allow them to stand up regardless of the current walk speed. elseif Crouching then Crouching = false Humanoid.WalkSpeed = NormalWS Humanoid.JumpPower = DefaultJumpPower Humanoid.JumpHeight = DefaultJumpHeight CrouchAnimm:Stop() end end ``` This modification ensures that the character can only enter the crouching state if they are not already crouching and their current walk speed does not match the `RunWalkSpeed` value. It allows the character to stand up from the crouching position regardless of the current walk speed, providing more flexibility in controlling the character's movement states. Remember to adjust the script according to your specific game design and mechanics, as the conditions for toggling crouching might vary based on how you want your game to behave.