0% found this document useful (0 votes)
12 views7 pages

Console Controlls

The document contains a Lua script for a character movement system in a game, defining various movement states such as Sprint, Jog, Walk, and Crouch, along with their respective animations and speeds. It handles user input for movement controls, stamina management, and animation playback based on the character's status. Additionally, it includes functionality to adjust movement speeds based on game effects and to track the player's status and stamina visually in the UI.

Uploaded by

hadezfrmdao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Console Controlls

The document contains a Lua script for a character movement system in a game, defining various movement states such as Sprint, Jog, Walk, and Crouch, along with their respective animations and speeds. It handles user input for movement controls, stamina management, and animation playback based on the character's status. Additionally, it includes functionality to adjust movement speeds based on game effects and to track the player's status and stamina visually in the UI.

Uploaded by

hadezfrmdao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

local Data = {

Sprint = {
Animation = 'rbxassetid://114074286473775';
Speed = 15;
};
Jog = {
Animation = 'rbxassetid://72252468099096';
Speed = 13;
};
Walk = {
Animation = 'rbxassetid://85191583024690';
Speed = 7;
};
Crouch = {
Animation = 'rbxassetid://121860168933610';
IdleAnimation = 'rbxassetid://89100355220321';
Speed = 4;
};
}

local UIS = game:GetService('UserInputService')


local Run = game:GetService('RunService')
local Player = game.Players.LocalPlayer

local FirstTapDone = true


local RunningOrSprinting = false

local Crouching = false

local onController = false

local Status = 'Walking'


local AnimationPlaying = false

local Stamina = 100

Player.Character.Humanoid.WalkSpeed = Data.Walk.Speed

local Character = Player.Character


local Humanoid = Character:WaitForChild('Humanoid')

local SprintAnimation = Instance.new('Animation')


SprintAnimation.AnimationId = Data.Sprint.Animation
SAnimation = Humanoid:LoadAnimation(SprintAnimation)

local JogAnimation = Instance.new('Animation')


JogAnimation.AnimationId = Data.Jog.Animation
JAnimation = Humanoid:LoadAnimation(JogAnimation)

local CrouchAnimation = Instance.new('Animation')


CrouchAnimation.AnimationId = Data.Crouch.Animation
CAnimation = Humanoid:LoadAnimation(CrouchAnimation)

local CrouchIdleAnimation = Instance.new('Animation')


CrouchIdleAnimation.AnimationId = Data.Crouch.IdleAnimation
CiAnimation = Humanoid:LoadAnimation(CrouchIdleAnimation)

local ShiftButtonDown = false


local MovementButtonDown = false

local CrouchStatus = 'Idle'

local SprintKeys = {
'LeftShift',
'ButtonL3',
}

UIS.InputBegan:Connect(function(i)
if table.find(SprintKeys,i.KeyCode.Name) and UIS:GetFocusedTextBox() == nil
and Status ~= 'Crouching' and not Player:FindFirstChild('IsInCar') then
ShiftButtonDown = true
if FirstTapDone == true then
FirstTapDone = false
Status = 'Sprinting'
AnimationPlaying = false
RunningOrSprinting = true
else
FirstTapDone = true
Status = 'Jogging'
AnimationPlaying = false
RunningOrSprinting = true
end

elseif i.KeyCode == Enum.KeyCode.LeftControl and UIS:GetFocusedTextBox() ==


nil and not Player:FindFirstChild('IsInCar') then
if RunningOrSprinting == false then
Status = 'Crouching'
CrouchStatus = 'Idle'
Crouching = true
AnimationPlaying = false
else
StopSprinting()
Status = 'Crouching'
CrouchStatus = 'Idle'
Crouching = true
AnimationPlaying = false
end

elseif i.KeyCode == Enum.KeyCode.Up and UIS:GetFocusedTextBox() == nil then


local INST = Instance.new('StringValue', script.KeysDown)
INST.Name = 'Up'
elseif i.KeyCode == Enum.KeyCode.Down and UIS:GetFocusedTextBox() == nil then
local INST = Instance.new('StringValue', script.KeysDown)
INST.Name = 'Down'
elseif i.KeyCode == Enum.KeyCode.W and UIS:GetFocusedTextBox() == nil then
local INST = Instance.new('StringValue', script.KeysDown)
INST.Name = 'W'
elseif i.KeyCode == Enum.KeyCode.A and UIS:GetFocusedTextBox() == nil then
local INST = Instance.new('StringValue', script.KeysDown)
INST.Name = 'A'
elseif i.KeyCode == Enum.KeyCode.S and UIS:GetFocusedTextBox() == nil then
local INST = Instance.new('StringValue', script.KeysDown)
INST.Name = 'S'
elseif i.KeyCode == Enum.KeyCode.D and UIS:GetFocusedTextBox() == nil then
local INST = Instance.new('StringValue', script.KeysDown)
INST.Name = 'D'
end
end)

function StopSprinting()
Status = 'Walking'
CrouchStatus = 'Idle'
AnimationPlaying = false
RunningOrSprinting = false
Player.Character.Humanoid.WalkSpeed = Data.Walk.Speed
SAnimation:Stop()
JAnimation:Stop()
CAnimation:Stop()
CiAnimation:Stop()
end

UIS.InputEnded:Connect(function(i)
if i.KeyCode == Enum.KeyCode.LeftShift and not
Player:FindFirstChild('IsInCar') then
ShiftButtonDown = false
wait(1.35)
if RunningOrSprinting == true and ShiftButtonDown == false then
StopSprinting()
end
elseif i.KeyCode == Enum.KeyCode.ButtonL2 and not
Player:FindFirstChild('IsInCar') then
ShiftButtonDown = false
wait(1.35)
if RunningOrSprinting == true and ShiftButtonDown == false then
StopSprinting()
end
elseif i.KeyCode == Enum.KeyCode.LeftControl and not
Player:FindFirstChild('IsInCar') then
if Status == 'Crouching' then
Crouching = false
StopSprinting()
end

elseif i.KeyCode == Enum.KeyCode.Up then


for i, key in pairs(script.KeysDown:GetChildren()) do
if key.Name == 'Up' then key:Destroy() end
end
elseif i.KeyCode == Enum.KeyCode.Down then
for i, key in pairs(script.KeysDown:GetChildren()) do
if key.Name == 'Down' then key:Destroy() end
end
elseif i.KeyCode == Enum.KeyCode.W then
for i, key in pairs(script.KeysDown:GetChildren()) do
if key.Name == 'W' then key:Destroy() end
end
elseif i.KeyCode == Enum.KeyCode.A then
for i, key in pairs(script.KeysDown:GetChildren()) do
if key.Name == 'A' then key:Destroy() end
end

elseif i.KeyCode == Enum.KeyCode.S then


for i, key in pairs(script.KeysDown:GetChildren()) do
if key.Name == 'S' then key:Destroy() end
end
elseif i.KeyCode == Enum.KeyCode.D then
for i, key in pairs(script.KeysDown:GetChildren()) do
if key.Name == 'D' then key:Destroy() end
end
end
end)

local StaminaDebouncer = false


local KeyDebouncer = false

Player.ChildAdded:Connect(function(child)
if child.Name == 'IsInCar' then
StopSprinting()
end
end)

local EffectDebouncer = false

Run.RenderStepped:Connect(function()

if KeyDebouncer == false then


KeyDebouncer = true
local KeysDown = 0
local KeyDownFolder = script:WaitForChild('KeysDown')
for i, key in pairs(KeyDownFolder:GetChildren()) do
KeysDown += 1
end

if KeysDown == 0 then
MovementButtonDown = false
else
MovementButtonDown = true
end
wait(0.5)
KeyDebouncer = false
end

local Fistsup = false


local Gunout = false

if script.Parent:FindFirstChild('FistClient') then
if script.Parent.FistClient:FindFirstChild('Variables') then
if script.Parent.FistClient.Variables:FindFirstChild('FistsUp')
then
if script.Parent.FistClient.Variables.FistsUp.Value == true
then
Fistsup = true
end
end
end
end

if Status ~= 'Walking' and Status ~= 'Crouching' then


if Character:FindFirstChildOfClass('Tool') then
if
Character:FindFirstChildOfClass('Tool'):FindFirstChild('Weapon.Local') then
if game.Workspace.CurrentCamera.FieldOfView == 56 or
game.Workspace.CurrentCamera.FieldOfView == 38 then
Gunout = true
end
end
end
end

if Status ~= 'Walking' then


if Gunout == true then
StopSprinting()
end

if MovementButtonDown == true and Fistsup == false and Gunout == false


then
if Status == 'Jogging' then
if AnimationPlaying == false then
AnimationPlaying = true
Player.Character.Humanoid.WalkSpeed = Data.Jog.Speed
SAnimation:Stop()
JAnimation:Play()
end
elseif Status == 'Sprinting' then
if AnimationPlaying == false then
AnimationPlaying = true
Player.Character.Humanoid.WalkSpeed =
Data.Sprint.Speed
SAnimation:Play()
JAnimation:Stop()
end
end
else
if Fistsup == false then
StopSprinting()
else
if Status ~= 'Crouching' then
StopSprinting()
end
end
end

if Status == 'Crouching' then


if MovementButtonDown == true then
if CrouchStatus ~= 'Moving' then
CrouchStatus = 'Moving'
Player.Character.Humanoid.WalkSpeed =
Data.Crouch.Speed
CiAnimation:Stop()
CAnimation:Play()
end
else
if CrouchStatus ~= 'Idle' then
CrouchStatus = 'Idle'
Player.Character.Humanoid.WalkSpeed =
Data.Crouch.Speed
CiAnimation:Play()
CAnimation:Stop()
end
end
end

else
if Player:FindFirstChild('Status') then
if Player:FindFirstChild('Status').Value == 'Normal' then
Player.Character.Humanoid.WalkSpeed = Data.Walk.Speed

end
end
end

if Player.PlayerGui:FindFirstChild('StatsUI') then
if Player.PlayerGui:FindFirstChild('StatsUI').Enabled == true then
local Formula = Stamina / 100
Player.PlayerGui.StatsUI.Content.Map.Stamina.Filler.Size =
UDim2.new(Formula, 0, 1, 0)
if Status == 'Walking' and Stamina < 90 then

Player.PlayerGui.StatsUI.Content.Map.Stamina.Filler.BackgroundColor3 =
Color3.fromRGB(173, 219, 255)
else

Player.PlayerGui.StatsUI.Content.Map.Stamina.Filler.BackgroundColor3 =
Color3.fromRGB(94, 168, 255)
end
end
end

if StaminaDebouncer == false then


StaminaDebouncer = true
if RunningOrSprinting == true then
if Stamina > 1 then
if Status == 'Jogging' then
Stamina -= 0.25
elseif Status == 'Sprinting' then
Stamina -= 0.5
end
else
StopSprinting()
end
else
if Stamina < 100 then
if (Stamina + 0.5) < 100 then
Stamina += 0.5
else
Stamina = 100
end
end
end
wait(0.1)
StaminaDebouncer = false
end

if script.Effects:FindFirstChildOfClass('NumberValue') or
script.Effects:FindFirstChildOfClass('BoolValue') or
script.Effects:FindFirstChildOfClass('StringValue') then
if script.Effects:FindFirstChild('SpeedBoost') then
Data.Sprint.Speed = 17
Data.Jog.Speed = 15
Data.Walk.Speed = 9
elseif script.Effects:FindFirstChild('SpeedLoss') then
Data.Sprint.Speed = 13
Data.Jog.Speed = 11
Data.Walk.Speed = 5
else
if Status == 'Sprinting' or Status == 'Jogging' or Status ==
'Crouching' then
if Data.Sprint.Speed ~= 15 then
Data.Sprint.Speed = 15
end
if Data.Jog.Speed ~= 13 then
Data.Jog.Speed = 13
end
if Data.Walk.Speed ~= 7 then
Data.Walk.Speed = 7
end
StopSprinting()
Player.Character.Humanoid.WalkSpeed = 7
end
end
end

if FirstTapDone == true then


if FirstTapDone == true then
wait(1.25)
FirstTapDone = false
end
end
end)

function ReturnRunStatus()
local RunStatus = Status
return RunStatus
end

local remotefunction = script:WaitForChild('GetRunStatus')


remotefunction.OnClientInvoke = ReturnRunStatus

game:GetService('RunService').RenderStepped:Connect(function()
local lastInput = UIS:GetLastInputType()

if lastInput == Enum.UserInputType.Gamepad1 then


onController = true
else
onController = false
end

if onController and Humanoid.MoveDirection ~= Vector3.new() then


local INST = Instance.new('StringValue', script.KeysDown)
if not script.KeysDown:FindFirstChild('W') then
INST.Name = 'W'
else
INST:Destroy()
end
elseif onController and Humanoid.MoveDirection == Vector3.new() then
if script.KeysDown:FindFirstChild('W') then
script.KeysDown:FindFirstChild('W'):Destroy()
end
end
end)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy