I tried to bind first action it work perfectly but I bind the second one and pressing “Q” it doesn’t work how am I going to fix this
local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
local Players = game:GetService("Players")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local StompEvent = Remotes:WaitForChild("StompEvent")
local SprintEvent = Remotes:WaitForChild("SprintEvent")
local MainModule = require(Modules:WaitForChild("MainModule"))
local BulkFade = require(Modules:WaitForChild("BulkFade"))
local ScreenGui = script.Parent
local MinAxis = math.min(ScreenGui.AbsoluteSize.X, ScreenGui.AbsoluteSize.Y)
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local IsSmallScreen = MinAxis <= 500
local ActionButtonSize = IsSmallScreen and 70 or 120
local Humanoid = MainModule.GetHumanoid(Character)
while not Humanoid do
Humanoid = MainModule.GetHumanoid(Character)
Character.ChildAdded:Wait()
end
local Animator = Humanoid:FindFirstChildOfClass("Animator")
while not Animator do
Animator = Humanoid:FindFirstChildOfClass("Animator")
Humanoid.ChildAdded:Wait()
end
local Sprinting = false
local Configuration = ScreenGui:WaitForChild("Configuration")
local MaxStamina = MainModule.Create("NumberValue", Humanoid){
Name = "MaxStamina",
Value = 100
}
local Stamina = MainModule.Create("NumberValue", Humanoid){
Name = "Stamina",
Value = MaxStamina.Value
}
local OriginalWalkSpeed = Humanoid.WalkSpeed
local TweenDelay = .3
local StompAnimation = Animator:LoadAnimation(script:WaitForChild("StompAnimation"))
local RunAnimation = Animator:LoadAnimation(script:WaitForChild("RunAnimation"))
local FadeOutConnection = nil
local Jumped = false
local DiedConnection = nil
local JumpRequestConnection = nil
local StaminaChangedConnection = nil
local HumanoidAncestryChangedConnection = nil
local StaminaReductionRate = Configuration:WaitForChild("StaminaDeductionAmount").Value
local StaminaReductionDelay = Configuration:WaitForChild("StaminaDeductionDelay").Value
local SprintSpeed = Configuration:WaitForChild("SprintSpeed").Value
local JumpCooldown = Configuration:WaitForChild("JumpCooldown").Value
local RegenerateDelay = Configuration:WaitForChild("StaminaRegenerationDelay").Value
local RegenerateValue = Configuration:WaitForChild("StaminaRegenerationAmount").Value
local StompCooldown = Configuration:WaitForChild("StompCooldown").Value
local StompDuration = Configuration:WaitForChild("StompDuration").Value
local StompDamage = Configuration:WaitForChild("StompDamage").Value
local Stomped = false
local Stamina_Red_Color = Color3.new(255/255, 28/255, 0/255)
local Stamina_Yellow_Color = Color3.new(250/255, 235/255, 0)
local Stamina_Green_Color = Color3.new(27/255, 252/255, 107/255)
local Bar = MainModule.Create("Frame"){
AnchorPoint = Vector2.new(.5, 0),
Name = "Bar",
BackgroundColor3 = Color3.fromRGB(0, 0, 0),
Position = GuiService:IsTenFootInterface() and UDim2.new(.5, 0, 1, -140) or UDim2.new(.5, 0, 1, -100),
Size = UDim2.new(.5, 0, 0, 15),
SizeConstraint = Enum.SizeConstraint.RelativeYY,
ZIndex = 4
}
local Fill = MainModule.Create("Frame", Bar){
Name = "Fill",
BorderSizePixel = 0,
BackgroundColor3 = Stamina_Green_Color,
Size = UDim2.fromScale(1, 1),
ZIndex = 5
}
local UIStroke = MainModule.Create("UIStroke", Bar){
ApplyStrokeMode = Enum.ApplyStrokeMode.Border,
Thickness = 10,
Transparency = .25
}
local UISizeConstraint = MainModule.Create("UISizeConstraint", Bar){
MaxSize = Vector2.new(365, 15)
}
local StaminaBarTween = BulkFade.CreateGroup({Bar, Fill, UIStroke}, TweenInfo.new(TweenDelay))
local RegenerateStamina = coroutine.create(function()
while task.wait(RegenerateDelay) do
if (Sprinting == false) and (Humanoid.MoveDirection.Magnitude > 0) and (Stamina.Value < MaxStamina.Value) then
Stamina.Value = Stamina.Value + RegenerateValue
end
end
end)
task.delay(TweenDelay, function()
Bar.Parent = ScreenGui
end)
StaminaBarTween:FadeOut()
local function Terminate()
DiedConnection:Disconnect()
JumpRequestConnection:Disconnect()
StaminaChangedConnection:Disconnect()
HumanoidAncestryChangedConnection:Disconnect()
ContextActionService:UnbindAction("SprintAction")
ContextActionService:UnbindAction("StompAction")
Bar:Destroy()
coroutine.yield(RegenerateStamina)
end
local function RescaleActionButton(ActionName)
local ActionButton = ContextActionService:GetButton(ActionName)
if ActionButton then
local ActionTitle = ActionButton:WaitForChild("ActionTitle")
if not IsSmallScreen then
ActionTitle.TextSize = 36
else
ActionTitle.TextSize = 18
end
ActionButton.Size = UDim2.fromOffset(ActionButtonSize, ActionButtonSize)
else
warn("This action doesn't exist.")
return
end
end
local function HandleSprint(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then
if (Sprinting == false) and (Stamina.Value > StaminaReductionRate) then
Sprinting = true
OriginalWalkSpeed = Humanoid.WalkSpeed
SprintEvent:FireServer(SprintSpeed)
repeat
task.wait(StaminaReductionDelay)
if Humanoid.MoveDirection.Magnitude > 0 then
Stamina.Value = Stamina.Value - StaminaReductionRate
end
until (Sprinting == false)
SprintEvent:FireServer(OriginalWalkSpeed)
end
elseif InputState == Enum.UserInputState.End then
if (Sprinting == true) then
Sprinting = false
SprintEvent:FireServer(OriginalWalkSpeed)
end
end
end
local function HandleStomp(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Begin and not Stomped then
Stomped = true
StompAnimation:Play()
if ContextActionService:GetButton(ActionName) then
MainModule.SetButtonCooldown(ActionName, StompCooldown)
end
StompEvent:FireServer(StompDuration, StompDamage)
task.wait(StompCooldown)
Stomped = false
end
end
StaminaChangedConnection = Stamina.Changed:Connect(function(Value)
if (Value < StaminaReductionRate) then
Sprinting = false
end
if Value < MaxStamina.Value then
StaminaBarTween:FadeIn()
else
StaminaBarTween:FadeOut()
end
local StaminaColorToPosition = {
[Vector3.new(Stamina_Red_Color.r, Stamina_Red_Color.g, Stamina_Red_Color.b)] = 0.1;
[Vector3.new(Stamina_Yellow_Color.r, Stamina_Yellow_Color.g, Stamina_Yellow_Color.b)] = 0.5;
[Vector3.new(Stamina_Green_Color.r, Stamina_Green_Color.g, Stamina_Green_Color.b)] = 0.8;
}
local Min = 0.1
local MinColor = Stamina_Red_Color
local Max = 0.8
local MaxColor = Stamina_Green_Color
local function StaminaBarColorTransferFunction(StaminaPercent)
if StaminaPercent < Min then
return MinColor
elseif StaminaPercent > Max then
return MaxColor
end
local NumeratorSum = Vector3.new(0,0,0)
local DenominatorSum = 0
for ColorSampleValue, SamplePoint in pairs(StaminaColorToPosition) do
local Distance = StaminaPercent - SamplePoint
if Distance == 0 then
return Color3.new(ColorSampleValue.X, ColorSampleValue.Y, ColorSampleValue.Z)
else
local Wi = 1 / (Distance * Distance)
NumeratorSum = NumeratorSum + Wi * ColorSampleValue
DenominatorSum = DenominatorSum + Wi
end
end
local Result = NumeratorSum / DenominatorSum
return Color3.new(Result.X, Result.Y, Result.Z)
end
local StaminaPercent = math.clamp(0, (Value / MaxStamina.Value), 1)
Fill:TweenSize(UDim2.fromScale(StaminaPercent, 1), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, .5, true)
Fill.BackgroundColor3 = StaminaBarColorTransferFunction(StaminaPercent)
end)
JumpRequestConnection = UserInputService.JumpRequest:Connect(function()
if not Jumped and Humanoid.FloorMaterial ~= Enum.Material.Air then
Jumped = true
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
task.wait(JumpCooldown)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
Jumped = false
end
end)
HumanoidAncestryChangedConnection = Humanoid.AncestryChanged:Connect(function(Child, Parent)
if not Parent then
Terminate()
end
end)
ContextActionService:BindAction("SprintAction", HandleSprint, true, Enum.KeyCode.LeftShift, Enum.KeyCode.ButtonL2)
ContextActionService:SetPosition("SprintAction", IsSmallScreen and UDim2.new(1, -(ActionButtonSize * 2.52 - 10), 1, -ActionButtonSize - 20) or
UDim2.new(1, -(ActionButtonSize * 2.52 - 10), 1, -ActionButtonSize * 1.75))
ContextActionService:SetTitle("SprintAction", "Sprint")
RescaleActionButton("SprintAction")
ContextActionService:BindAction("StompAction", HandleStomp, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonX)
ContextActionService:SetPosition("StompAction", IsSmallScreen and UDim2.new(1, -(ActionButtonSize * 2.52 - 10), 1, -ActionButtonSize - 92) or
UDim2.new(1, -(ActionButtonSize * 2.52 - 10), 1, -ActionButtonSize * 2.77))
ContextActionService:SetTitle("StompAction", "Stomp")
RescaleActionButton("StompAction")
DiedConnection = Humanoid.Died:Connect(Terminate)
coroutine.resume(RegenerateStamina)