#Crouch not, crouching

1 messages · Page 1 of 1 (latest)

gilded mountain
#

This is the crouch script

Its a LocalScript in StarterPlayerCharacters

#

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

gilded mountain
gilded mountain
low karma
#

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

gilded mountain
#

the movement was made a month ago

#

i js came up with the crouch

gilded mountain
#

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

low karma
#

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

gilded mountain
#

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

toxic dragonBOT
#

studio** You are now Level 5! **studio

vocal crown
#

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

gilded mountain
#

okok

low karma
#

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

vocal crown
#

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:

  1. the FSM, just handling inputs and states, this will also tell the other systems when to activate and deactive
  2. the crouch script (both a function to enable and to disable
  3. 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
gilded mountain
#

okok, i think i can figure it out