#Crouch not, crouching
1 messages · Page 1 of 1 (latest)
This is the sprint script
its a LocalScript in StarterPlayerScripts, its called PlayerMovement
The problem?
Its requiring the player to sprint before actually being able to crouch, ontop of that, the player isnt crouching, they're just floating
tldr
this script requires
this script, in order for you to crouch
i feel like youve done a whole lot instead of piece by piece and now your facing multiple issues
so you just want when player presses "F" crouch
i just want them to not float
since i made the crouch thing a month after the movement, i cant figure out how to pair them
im also tryna figure out how to put it all as one script
that sounds like a module script to me
making your movement modular with some functions and a handler for player input
if player clicks shift send to function in module that makes them sprint
if player clicks c send to function in module that makes them crouch
yeah but for some reason, you need to sprint before you can crouch, its a seperate script, as it should detects the players movement speed, 14 or less, C will crouch, 15 or higher, it will slide
** You are now Level 5! **
I would recommend making a simple FSM to control both the crouching and sprinting. An FSM basically controls other code, and makes sure that multiple things cannot occur at the same time, i.e. crouching while sprinting
okok
incase you havent dealt with module scripts before this is the logic
-- MovementModule
local MovementModule = {}
function MovementModule.Sprint()
print("sprint")
end
function MovementModule.Crouch()
print("crouch")
end
return MovementModule
its really that simple js gotta get use to it
An FSM is basically just code that manages the "state" of something (in this case, the player). Here you would have states such as:
- default (normal walking)
- sprinting
- crouching
Then you just add in logic based on inputs to switch between those states, e.g.
default -> player presses shift (sprint) -> enter sprinting
sprinting -> player presses ctrl -> sprinting (failed to enter crouch, as player is not in default)
croughing -> player presses shift -> sprinting (no longer crouched)
All you need to set this up is:
- the FSM, just handling inputs and states, this will also tell the other systems when to activate and deactive
- the crouch script (both a function to enable and to disable
- a sprint script (both a function to enable and to disable)
enable and disable can be as simple as
local ExampleModule = {}
function ExamplemModule.Enable()
plr.WalkSpeed = 30
end
function Example.Disable()
plr.Walkspeed = 15
end
okok, i think i can figure it out