Not binding button when character changes

Hey! I made a working special attack for mobile and I want it to be usable only when a specific tool is enabled. I got an idea to use GetPropertyChanged on the character because when you equip a tool, it goes to your character. So I did that and used a pairs loop to scan for the specific tool. Problem is, its not doing anything. it didn’t even print anything to

(this is a local script inside startercharacterscripts)

player:GetPropertyChangedSignal("Character"):Connect(function()
	print("something changed!!")
	for i,v in pairs(character:GetChildren()) do
		if v:IsA("Tool") then
			print(v)
			if v.ClassName == "Hells Doom" then
				ContextActionUtility:BindAction("Special",Special, true, Enum.KeyCode.E)
				ContextActionUtility:SetTitle("Special","Special")
			end
			if v.ClassName ~= "Hells Doom" then
				ContextActionUtility:UnbindAction("Special")
			end
		end
	end
end)

Use .ChildAdded.

New code:

character.ChildAdded:Connect(function(child)
	print("something changed!!")

	if child:IsA("Tool") then
		print(child)
		
		if child.ClassName == "Hells Doom" then
			ContextActionUtility:BindAction("Special", Special, true, Enum.KeyCode.E)
			ContextActionUtility:SetTitle("Special", "Special")
		end
		
		if child.ClassName ~= "Hells Doom" then
			ContextActionUtility:UnbindAction("Special")
		end
	end
end)
1 Like

the print works but for some reason it’s not binding the tool

Try this:

character.ChildAdded:Connect(function(child)
	print(child)
	
	if child.Name == "Hells Doom" then
		ContextActionUtility:BindAction("Special", Special, true, Enum.KeyCode.E)
		ContextActionUtility:SetTitle("Special", "Special")
	end
end)

character.ChildRemoved:Connect(function(child)
	print(child)

	if child.Name == "Hells Doom" then
		ContextActionUtility:UnbindAction("Special")
	end
end)
1 Like