so basically I have a function that connects the binds the context after the player equips the tool
but the problem is it doesnt work it doesnt print out 1 but it prints out if i move the print outside the if condition
local SET_BEAM = "Set Beam"
local SETBEAM_KEY = Enum.KeyCode.I
local function onSetBeam(actionName,inputState,inputObj)
if isEquipped == false then return end
if inputState == Enum.UserInputState.Begin then
print(1)
end
end
--// Equip Functions
Tool.Equipped:Connect(function()
isEquipped = true
Equip_Anim:Play()
Equip_Anim.KeyframeReached:Connect(function(keyFrame)
if keyFrame == "Finish_Equip" then
Idle1_Anim:Play()
-- Bind Contexts
print("bind")
ContextActionService:BindAction(SET_BEAM,onSetBeam,false,SETBEAM_KEY)
end
end)
end)
yes it gets fired the print(“bind”) does print Ive worked with contextactionservice before and I know that should work I even checked my previous scripts on contextactionservice and its the same but somehow on the script it doesnt work
--// Services
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
--// Player
local LPlayer = Players.LocalPlayer
local Char = LPlayer.Character or LPlayer.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
LPlayer.CharacterAdded:Connect(function(char)
Humanoid = char.Humanoid
end)
--// Directories
local Tool = script.Parent.Parent
local Handle = Tool:WaitForChild("Handle")
local Handlers = Tool:WaitForChild("Handlers")
local Events = Handlers:WaitForChild("Events")
local Animations = Handlers:WaitForChild("Animations")
--// Events
local SetBeam = Events:WaitForChild("SetBeam")
--// Context
local CHANGE_FORM = "Change Form"
local SET_BEAM = "Set Beam"
--// Keys
local CHANGEFORM_KEY = Enum.KeyCode.K
local SETBEAM_KEY = Enum.KeyCode.I
--// Animations
local Idle1_Anim = Humanoid.Animator:LoadAnimation(Animations:WaitForChild("Idle_1"))
local Equip_Anim = Humanoid.Animator:LoadAnimation(Animations:WaitForChild("Equip"))
--// SFX
local IgniteSFX = Handle:WaitForChild("Ignite")
local DisIgniteSFX = Handle:WaitForChild("DisIgnite")
local ClashSFX = Handle:WaitForChild("Clash")
local HitSFX = Handle:WaitForChild("Hit")
local HumSFX = Handle:WaitForChild("Hum")
local Swing1SFX = Handle:WaitForChild("Swing_1")
local Swing2SFX = Handle:WaitForChild("Swing_2")
--// Values
local isEquipped = false
local isIgnite = false
local currentForm = 1
--// Functions
local function onSetBeam(actionName,inputState,inputObj)
if isEquipped == false then return end
if inputState == Enum.UserInputState.Begin then
print(1)
end
end
--// Equip Functions
Tool.Equipped:Connect(function()
isEquipped = true
Equip_Anim:Play()
Equip_Anim.KeyframeReached:Connect(function(keyFrame)
if keyFrame == "Finish_Equip" then
Idle1_Anim:Play()
-- Bind Contexts
print("bind")
ContextActionService:BindAction(SET_BEAM,onSetBeam,false,SETBEAM_KEY)
end
end)
end)
Tool.Unequipped:Connect(function()
isEquipped = false
isIgnite = false
Equip_Anim:Stop()
Idle1_Anim:Stop()
--// Unbind Contexts
ContextActionService:UnbindAction(SET_BEAM)
end)