So basically i have 2 local scripts, the first one plays a backflip animation when i press the F key

--//Service
local CAS = game:GetService('ContextActionService')

--//Variables
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')

--//Animation
local flipAnimation = script:WaitForChild('Backflip')
local load = hum:LoadAnimation(flipAnimation)


--//Function
function blank(actionName, inputState, input)
	if actionName == 'BackFlip' and inputState == Enum.UserInputState.Begin then
		load:Play()
		
		CAS:UnbindAction('LeftClick')
	end
end


CAS:BindAction('BackFlip', blank, false, Enum.KeyCode.F)

The second local script is located inside a tool, when i click while having the tool equipped, it will print out "working"

local CAS = game:GetService('ContextActionService')

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local tool = script.Parent


function clicked(actionName, inputState, input)
	if actionName == 'LeftClick' and inputState == Enum.UserInputState.Begin then
		print('working')
	end
end


tool.Equipped:Connect(function()
	CAS:BindAction('LeftClick', clicked, false, Enum.UserInputType.MouseButton1)
end)

What i want to do is, i want to prevent the tool from being clickable when i do the backflip animation. This is to prevent the animations from overriding each other once i add animations to the tool when clicked. I know that i can use UnbindAction whenever i press the F key to disable to clicking but how am i suppose to enable it again from a different local script?

3 comments

0

Why are you completely unbinding leftclick to do this? I think that having a boolvalue under the character which would be true if the player is doing an animation would be better but I'm no professional

0

Yeah you're right, but i'd have to create bindable events to allow the 2 local scripts to communicate with each other. I'm gonna have many different animations binded to keys in the future so i'm not sure if it's a good idea to create a bunch of bindable events just to disable a key/mouseclick for a short duration.

1

If you are going to use many animations in the future BindableEvents would be less scalable. I suggest having a way for the local player to know that they are in an action. I personally use a module script that contains the state of the player so I can do if Module.InAction then play animation.