Im making a “pass” script that charges power and then when u release it sets a “actionTriggered” variable to true (basically the to kick variable) but my problem is that it is not picking up when the inputState ends for some reason?
local function pass(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject)
if actionName ~= "Pass" then
return
end
if ToolController:isUsing() then
return
end
if inputState == Enum.UserInputState.Begin then
print("BEGAN")
ToolController:setUsing(true)
ToolController:setCharging(true)
power = 35
while ToolController:isCharging() do
power = math.min(power + 1.1, MAX_POWER)
task.wait(.02)
end
elseif inputState == Enum.UserInputState.End then
print("ENDED")
if ToolController:isUsing() and ToolController:isCharging() then
torso.CollisionGroup = "Character"
ToolController:setCharging(false)
actionTriggered = true
task.delay(.5, function()
torso.CollisionGroup = "Default"
actionTriggered = false
end)
task.delay(.75, function()
ToolController:setUsing(false)
ToolController:setCharging(false)
end)
end
end
end
Here is the moduleScript for the ToolController, it just prevents multiple things from being activated at once in other scripts and it has some helper funcs.
local Debris = game:GetService("Debris")
local isUsing = false
local isCharging = false
local currentLeg = "Right Leg"
local ToolController = {}
function ToolController:applyVelocity(parent: Part, maxForce: Vector3, velocity: Vector3)
for _, instance in pairs(parent:GetChildren()) do
if instance:IsA("BodyVelocity") then
instance:Destroy()
end
end
local reactVelocity = Instance.new("BodyVelocity")
reactVelocity.MaxForce = maxForce
reactVelocity.Velocity = velocity
reactVelocity.Parent = parent
Debris:AddItem(reactVelocity, .3)
end
function ToolController:isUsing(): boolean
return isUsing
end
function ToolController:setUsing(using: boolean?)
isUsing = using
end
function ToolController:isCharging(): boolean
return isCharging
end
function ToolController:setCharging(charging: boolean?)
isCharging = charging
end
function ToolController:getCurrentLeg(): string
return currentLeg
end
function ToolController:setCurrentLeg(leg: string?)
currentLeg = leg
end
return ToolController